Hi,
I don't know if this is possible, but if anyone can answer, must it be you guys
I have this userform, where I have a code that tells you, if you forgot to fill out a box.
I would love to have it so the userform closes after you have pressed the Add button.
If i use a "unload me" in the vba, is there a Rune-time error 2110, because it cant make focus on the boxes you didnt fill out.
So in my eyes do I have the option to have the msgbox telling you miss a box OR that the userform closes after pressing the Add button.
Is there a way to make both work?
This is the code
Code:
Private Sub Label1_Click()
If Len(Label1.Caption) <> 0 Then
Shell "explorer.exe" & " " & Label1.Caption, vbNormalFocus
End If
End Sub
Private Sub Add_Click()
If Theme.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Theme")
Theme.SetFocus
Exit Sub
End If
If Age.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Age")
Age.SetFocus
Exit Sub
End If
If Gender.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Gender")
Gender.SetFocus
Exit Sub
End If
If Resp.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Responsible")
Resp.SetFocus
Exit Sub
End If
If Month.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Month")
Month.SetFocus
Exit Sub
End If
If Year.ListIndex = -1 Then
Cancel = 1
MsgBox ("Please Select Year")
Year.SetFocus
Exit Sub
End If
If Label1 = "" Then
Cancel = 1
MsgBox ("Please Select Folder")
Exit Sub
End If
Dim erow As Long
Arow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Arow, 7).Value = Type1.Value
If Type1.Value <> "" Then
Cells(Arow, 1).Value = Theme.Value
Cells(Arow, 2).Value = Val(Age.Text)
Cells(Arow, 3).Value = Gender.Value
Cells(Arow, 4).Value = Resp.Text
Cells(Arow, 5).Value = Month.Value
Cells(Arow, 6).Value = Year.Value
Cells(Arow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(Arow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
Brow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Brow, 7).Value = Type2.Value
If Type2.Value <> "" Then
Cells(Brow, 1).Value = Theme.Value
Cells(Brow, 2).Value = Val(Age.Text)
Cells(Brow, 3).Value = Gender.Value
Cells(Brow, 4).Value = Resp.Text
Cells(Brow, 5).Value = Month.Value
Cells(Brow, 6).Value = Year.Value
Cells(Brow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(Brow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
Crow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Crow, 7).Value = Type3.Value
If Type3.Value <> "" Then
Cells(Crow, 1).Value = Theme.Value
Cells(Crow, 2).Value = Val(Age.Text)
Cells(Crow, 3).Value = Gender.Value
Cells(Crow, 4).Value = Resp.Text
Cells(Crow, 5).Value = Month.Value
Cells(Crow, 6).Value = Year.Value
Cells(Crow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(Crow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
Drow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Drow, 7).Value = Type4.Value
If Type4.Value <> "" Then
Cells(Drow, 1).Value = Theme.Value
Cells(Drow, 2).Value = Val(Age.Text)
Cells(Drow, 3).Value = Gender.Value
Cells(Drow, 4).Value = Resp.Text
Cells(Drow, 5).Value = Month.Value
Cells(Drow, 6).Value = Year.Value
Cells(Drow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(Drow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 7).Value = Type5.Value
If Type5.Value <> "" Then
Cells(erow, 1).Value = Theme.Value
Cells(erow, 2).Value = Val(Age.Text)
Cells(erow, 3).Value = Gender.Value
Cells(erow, 4).Value = Resp.Text
Cells(erow, 5).Value = Month.Value
Cells(erow, 6).Value = Year.Value
Cells(erow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(erow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
Frow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(Frow, 7).Value = Type6.Value
If Type6.Value <> "" Then
Cells(Frow, 1).Value = Theme.Value
Cells(Frow, 2).Value = Val(Age.Text)
Cells(Frow, 3).Value = Gender.Value
Cells(Frow, 4).Value = Resp.Text
Cells(Frow, 5).Value = Month.Value
Cells(Frow, 6).Value = Year.Value
Cells(Frow, 8).Value = Label1.Caption
ActiveSheet.Hyperlinks.Add Anchor:=Cells(Frow + 0, 8), Address:=Label1.Caption, TextToDisplay:=Label1.Caption
End If
End Sub
Private Sub Label9_Click()
End Sub
Private Sub Source_Click()
Dim FolderPath As Object
With Label1
.BackStyle = fmBackStyleTransparent
.Font.Name = "Courier New"
.Font.Underline = True
.Font.Bold = True
.Font.Size = 10
.WordWrap = False
.ForeColor = vbBlue
.ControlTipText = "Click Link to open folder."
Set FolderPath = CreateObject("Shell.Application").BrowseForFolder(0, "Select a Folder...", 0, 0)
If Not TypeName(FolderPath) = "Nothing" Then Label1.Caption = FolderPath.Items.Item.Path
End With
Set FolderPath = Nothing
End Sub
Private Sub Clear_Click()
Dim c As Control
For Each c In Me.Controls
Select Case TypeName(c)
Case "TextBox", "ComboBox"
c.Text = ""
End Select
Next c
End Sub
Private Sub UserForm_Initialize()
Label1.Caption = ""
Label1.BackStyle = fmBackStyleTransparent
End Sub