Need help with simple code

mitchem1

Registered User.
Local time
Yesterday, 21:27
Joined
Feb 21, 2002
Messages
153
I have a very simple form that users will use to locate a permit. The form has two fields, cboYear and cboReferenceNumber, and one command button, cmdFindPermit. The form works fine. However, the user will be required make selections from both fields and I would like to add code that produces a message box if either or both are not selected (when cmdFindPermit is clicked). For example, if cboYear and cboReferenceNumber are not selected, the message should say, "Please enter a year" and return the cursor to cboYear. If cboYear is entered, but not cboReferenceNumber, the code should do the same except for Reference Number. Thanks for any ideas.
 
Code - Msgbox if Combobox is empty or no value chosen

Something like this??


Private Sub cmdFindPermit_Click()

If (Me.cboReferenceNumber = "" Or IsNull(Me.cboReferenceNumber)) Then

MsgBox "You must choose a reference."
Me.cboReferenceNumber.SetFocus

Exit Sub
End If

If (Me.cboYear = "" Or IsNull(Me.cboYear)) Then

MsgBox "You must choose a reference."
Me.cboReferenceNumber.SetFocus

Exit Sub
End If

<your code>

EndSub


Not sure if it'll work... try it. It worked for something similiar..
 
Last edited:
Thanks, I'll give it a try.
 

Users who are viewing this thread

Back
Top Bottom