How I get a MsgBox to appear for a query that doesn't produce data

C

Charles

I have a Access DB that will query a table looking for a specific date. I
would like a message box to appear when the query doesn't have any data for
that date. When data is present for a date the query usually will open an
report and displays it.
 
F

fredg

I have a Access DB that will query a table looking for a specific date. I
would like a message box to appear when the query doesn't have any data for
that date. When data is present for a date the query usually will open an
report and displays it.

Queries don't open reports.
Reports use a query as their record source.
If the query is the Record Source of a report, code the Report's
OnNoData event:

MsgBox "No data to report for this period."
Cancel = True

If the report has been opened from an event this will generate Error
2501.
Trap the error in that event.
 
Top