Cancelling report if no data

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

I am using a form to select criteria for a report -
however if the user selects criteria that has no data for
the report the report prints with blank a record. Can I
stop the report printing and give the user a message that
there is no info for the report instead
 
Reports have a NoData event, especially for this purpose.
Cancel that event, either with an event procedure, or a CancelEvent action
in a macro.

If you used an event procedure to open the report, trap error 2501 - the
message Access gives back to your code to say the report did not actually
open.
 
Peter said:
I am using a form to select criteria for a report -
however if the user selects criteria that has no data for
the report the report prints with blank a record. Can I
stop the report printing and give the user a message that
there is no info for the report instead


Use the report's NoData event to display a message and to
Cancel the report:

Sub Report_NoData( . . .
MsgBox "There are no records for this report"
Cancel = True
End Sub
 
I was looking at the Northwind sample and it has a report that does exactly
what you describe.
 
Thanks to all I feel pretty dim that I hadn't seen that
for myself - wood for the trees and all that!
 
Back
Top