Message box if query returns no records

G

George

How do I get a query (or macro that runs the query) to
display a message box "No records found" if no records
are found.
Thanks in anticipation
 
D

Dale Fye

Depends on what you are using the query for.

If it is the recordsource for a report, you can use the Nodata event
to display your message.

If it is for a form, in the Open event of the form, you can add some
code that checks to see whether the record count = 0 and if so,
display your message.

If you want to check before you open one of these events, you coud use
DLOOKUP("IdFieldName", "queryName") to get the first record from your
query. IF DLOOKUP returns NULL, you know there are no records in the
query(you need to make sure that the field you use in the DLOOKUP
cannot contain any null values). I use DLOOKUP rather than DCOUNT
because if the query has lots of records, it could take a while to
count all of them.

--
HTH

Dale Fye


How do I get a query (or macro that runs the query) to
display a message box "No records found" if no records
are found.
Thanks in anticipation
 

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