Message Box Instead of Error

T

TotallyConfused

How can get a message box to pop up when there are no records in a report
that says, "No Records"? On my switchboard I have a list of reports, when I
click on button report will display data and if no data it displays blank
page. I rather a message comes up saying no records for specific report.
Thank for any help on this question.
 
F

fredg

How can get a message box to pop up when there are no records in a report
that says, "No Records"? On my switchboard I have a list of reports, when I
click on button report will display data and if no data it displays blank
page. I rather a message comes up saying no records for specific report.
Thank for any help on this question.

Code the Report's OnNoData event:
MsgBox "No records to report on."
Cancel = True

Unfortunately, this will cause an error.
You need to trap the error (2501) in whatever event you used to open
the form.

Code that switchboard event:

On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acViewPreview
Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
 
T

TotallyConfused

Thank you for your response. Once I trap this error, will this eliminate
anymore error messages?
 
F

fredg

Thank you for your response. Once I trap this error, will this eliminate
anymore error messages?

Well, no. It will only eliminate the message regarding error 2501.
if you get a different error, then the Else portion of the code will
run and Access will give the error number and description message so
that you can take the necessary steps to correct that error.
 

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