Auto-Close Report If No Data

  • Thread starter Thread starter MDW
  • Start date Start date
M

MDW

I'm sure this is a fairly common question.

I'm running Access97. I've got a report that displays
shipment info, and users can enter dates (or date ranges)
on a form to limit which records are returned in the
report.

Of course, there are some dates where there simply are NO
shipments. Right now, the report displays that "#Error"
message in all the controls, which I know just means there
is no data to display.

But....is there any way for the report to detect that it
doesn't have any data, maybe pop up a MsgBox or something
and then just close?

Thx.
 
MDW said:
I'm running Access97. I've got a report that displays
shipment info, and users can enter dates (or date ranges)
on a form to limit which records are returned in the
report.

Of course, there are some dates where there simply are NO
shipments. Right now, the report displays that "#Error"
message in all the controls, which I know just means there
is no data to display.

But....is there any way for the report to detect that it
doesn't have any data, maybe pop up a MsgBox or something
and then just close?

Use the report's NoData event to execute a MsgBox and then
Cancel the report:

MsgBox "There is no data for " & vbcrlf _
& Forms!theform.txtstartdate & " to " _
& Forms!theform.txtenddate
Cancel = True

Canceling the report will trigger an unable to complete kind
of error back in the form's OpenReport method so be sure to
trap and ignore the 2501 error code.
 
Back
Top