Hi! I found a very old thread that gave me the basis for this but I can't seem to expand it as I need to. ctrl.Value does not seem to be recognized.
My goal is this:
-If it's a text box or combo box, required and blank = change background color
-If it's a check box or option button, required and false = change background color
Any help would be greatly appreciated!
My goal is this:
-If it's a text box or combo box, required and blank = change background color
-If it's a check box or option button, required and false = change background color
Any help would be greatly appreciated!
Code:
Sub Validate()
Dim ctrl As Control
setColor = RGB(255, 244, 164)
foundrequired = 0
For Each ctrl In Form_Submissions.Controls
If ctrl.ControlType = acTextBox Or ctrl.ControlType = acComboBox Then
If InStr(1, ctrl.Tag, "*") <> 0 And ctrl.Value = "" Then
ctrl.BackColor = setColor
foundrequired = foundrequired + 1
End If
End If
If ctrl.ControlType = acCheckBox Or ctrl.ControlType = acOptionButton Then
If InStr(1, ctrl.Tag, "*") <> 0 And ctrl.Value = False Then
ctrl.BackColor = setColor
foundrequired = foundrequired + 1
End If
End If
Next
If foundrequired > 0 Then
MsgBox "Please fill in the required fields before submitting.", vbCritical, "HOTEL CHECKS"
Exit Sub
End If
'continue code if passes validation
End Sub