How do I, for a Report with No data, Give a Message and Close It?

G

Guest

When a report has no data, I would like to give the user a message and then
close the report. I tried the 'On No Data' event of the report, but I can't
close the report from there, at least not with DoCmd.close acReport.

Would appreciate any help/ideas?
 
A

Allen Browne

Just cancel the No Data event, e.g.:
Private Sub Report_NoData(Cancel As Integer)
Cancel = True
End Sub

You can add a MsgBox if you want to tell the user about it.

If you opened the report programmatically, you will also need to trap error
2501 in the code that fired the OpenReport if you want to suppress that
message.
 
G

Guest

On the On No Data event write the code

Msgbox "No data"
cancel = true ' will close the report
 
R

RuralGuy

You don't Close the report in the Report_NoData event, you Cancel the opening of
the report. Cancel = True will stop the report from opening.

When a report has no data, I would like to give the user a message and then
close the report. I tried the 'On No Data' event of the report, but I can't
close the report from there, at least not with DoCmd.close acReport.

Would appreciate any help/ideas?

_______________________________________________
hth - RuralGuy (RG for short)
Please post to the NewsGroup so all may benefit.
 

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