report event - on no data

M

MSD

I'm basing a report on a query that sometimes returns an empty record set. I
have tried writing a macro that shows a message box if there are no records
to print and then closes the report.

However, this always produces an error:

This action can not be carried out while processing a report.

How can I exit from the report if there are no records to print?

Thanks very much,

Emma
 
D

Duane Hookom

It is quite simple to add VBA code in the On No Data event of the report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are no records in this report."
Cancel = True
End Sub

If the report is opened from code, you may need to add error handling to the
opening code to ignore err 2501.
 
Top