Combo Box Validation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write a simple procedure to be sure a selection has been made
from a combo box. I would like to call the procedure from the click event of
each button on a form.
My code is

Sub ValidatePeriod()
If IsNull(Combo1) Then
MsgBox "You must select a Month"
Combo1.SetFocus
Else
If Not IsNull(Combo1) Then
Exit Sub
End If

End If

End Sub

After I click OK on the message box the code drops through and continues the
event, without allowing the chance to select a choice. This code works fine
if I put in each procedure, which I am trying to avoid doing.
 
Use this code as a function that returns True Or False

Function ValidatePeriod()
ValidatePeriod = True
If IsNull(Me.Combo1) Then
MsgBox "You must select a Month"
Combo1.SetFocus
ValidatePeriod = False
End If

End Function

On the OnClick event of each button call the function, if it returns True
continue with the code, else exit without execute

If ValidatePeriod = True Then

Your code

End If
 
Back
Top