Error Message for FORM/QUERY if wrong number entered

K

kealaz

I have a form whose Record Source is a query.

The query pulls information from a table based on information entered by
the user, using the following in the Criteria.

Like [Enter Drawing Number:] & "*"

Right now, if an incorrect number is entered, I get a blank form. I would
like to have an error message appear if the number entered is not in the
drawing or part log.

Msgbox "Invalid drawing number. Please re-enter."

What code would I use, and where would I put it?

Thanks so much for your assistance!!!
 
D

Dirk Goldgar

kealaz said:
I have a form whose Record Source is a query.

The query pulls information from a table based on information entered by
the user, using the following in the Criteria.

Like [Enter Drawing Number:] & "*"

Right now, if an incorrect number is entered, I get a blank form. I would
like to have an error message appear if the number entered is not in the
drawing or part log.

Msgbox "Invalid drawing number. Please re-enter."

What code would I use, and where would I put it?


You can detect and respond to this condition in the form's Load event:

'----- start of code -----
Private Sub Form_Load()

If Me.RecordsetClone.RecordCount = 0 Then

' Remove the following statement if you want to
' keep the form open, though empty.
DoCmd.Close acForm, Me.Name, acSaveNo

MsgBox _
"Invalid drawing number. Please re-enter.", _
vbInformation, "No Record Found"

End If

End Sub
'----- end of code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top