Here's a Validate function I wrote and use in a lot of different forms.
Code:
Public Function Validate(ByRef ctrlBox As Control) As BooleanIf ctrlBox.ControlType = 106 Then
If ctrlBox Then 'validates that the checkbox has been checked
Validate = True
ctrlBox.BorderColor = RGB(31, 73, 125)
Exit Function
End If
End If
If ctrlBox.ControlType = 109 Or ctrlBox.ControlType = 111 Then
If Not IsNull(ctrlBox.value) And ctrlBox.value <> "" Then
Validate = True
ctrlBox.BorderColor = RGB(31, 73, 125)
Exit Function
End If
End If
ctrlBox.BorderColor = RGB(255, 0, 0)
If ctrlBox.Tag <> "" Then
MsgBox ctrlBox.Tag, vbCritical, "Data Validation Failed"
End If
ctrlBox.SetFocus
Validate = False
End Function
Just type your validation error message into the Tag field of each control and when you want to validate, pass it to this function. You can change up the decoration as you please - mine goes Red to Blue. It also sets focus on the failed control.
So if you want it to check on a particular value in your Combobox you could do something like
Code:
Select Case cboSomething
Case "Your Mom"
if Validate(txtYourmom) then
RunThisFunction
end if
Case "DIAF"
if Validate(chkInferno) then
RunThatFunction
end if
Case Else
if Validate(cboSomething) then
RunThisAndThatFunction
End If
End Select
If validation fails, the Validate function will set the focus, border red, and provide an error message if one is in the Tag field.