Auto-Close Report If No Data

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.
 
M

Marshall Barton

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.
 

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