Help Needed: Message Box Error Message

S

Steph

I have a query set up to look up records that contain a
certain value in a text box (txtSortByIONumb) on a form
(SearchBy). I have the following expression under the
query criteria:

Like Nz([Forms]![SearchBy]![txtSortByIONumb],"*")

If a user enters a value in the text box that is not in
the database, how do I create an error message to pop up
that says "This value does not exist. Please enter
another value."

Thanks,

Steph
..
 
A

Allen Browne

Queries can't do that, as they are not really designed as a user interface.

However, you could make a form in datasheet view (looks like a query) based
on this query, and cancel its Open event if there are no records:
Private Sub Form_Open(Cancel As Integer)
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No matches. Try again."
Cancel = True
End If
End Sub

Alternatively, if the target were a report, you could cancel the report's
NoData event.
 

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

Similar Threads

Error Message 2
Refresh control on form 2
Parameter Value error in a Subform 0
Access #Error & Excel Pivot 0
Access sub form help needed 2
Adding a Message Box ? 2
Message Box 3
Query Results in a Text Box 3

Top