Message Box Instead of Error

  • Thread starter Thread starter TotallyConfused
  • Start date Start date
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.
 
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
 
Thank you for your response. Once I trap this error, will this eliminate
anymore error messages?
 
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.
 
Back
Top