Hello All,
Im a noob when it comes to VBA userforms and I'm going around in circles with this problem. I have put together this code that checks if a .Tag caption has "MUST" in it then checks to see if the text or combo boxes have entries in and if the don't a MsgBox pops up and says you have missed X please fill it out. It kind of works as it does check the text and comboBoxs but in a random order (Middle - Top - Bottom ) - so my question is... is there a way to get it to check from the 1st box on the form and then step through them in order?
The workbook, userform and code are attached. code below.
Thanks in advance.
Private Sub SaveButton_Click()
'Writing to the databases
'After you have entered details in to the form this writes to the database
Dim emptyRow As Long
Dim cCont As Control
'FILL ALL MANDATORY CONTROLS TAG PROPERTIES WITH "MUST"
For Each cCont In Me.Controls
If UCase(cCont.Tag) = "MUST" Then
If cCont = vbNullString Then
MsgBox "Missing Data in " & cCont.Name
cCont.SetFocus
Exit Sub
End If
End If
Next cCont
'Make Sheet active
Sheet8.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = YearComboBox.Value
Cells(emptyRow, 2).Value = CompanyComboBox.Value
Cells(emptyRow, 3).Value = SiteComboBox.Value
Cells(emptyRow, 4).Value = TestTypeL1ComboBox.Value
Cells(emptyRow, 5).Value = TestTypeL2ComboBox.Value
Cells(emptyRow, 6).Value = TestTypeL3ComboBox.Value
Cells(emptyRow, 7).Value = TotSamplesTextBox.Value
Cells(emptyRow, 8).Value = Results1TextBox.Value
Cells(emptyRow, 9).Value = Results2TextBox.Value
Cells(emptyRow, 10).Value = Results3TextBox.Value
End Sub
Bookmarks