View Full Version : Need help with simple code


mitchem1
08-27-2002, 02:03 PM
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.

Cosmos75
08-27-2002, 02:20 PM
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..

mitchem1
08-28-2002, 06:06 AM
Thanks, I'll give it a try.