Supress Message

D

Dave

I have the following code in a VBA report module that is designed to alert
the user when the report is blank (i.e., no records):

Private Sub Report_NoData(Cancel As Integer)

On Error GoTo ErrorHandler

MsgBox "There are no records available for your selection."
Cancel = True
....

The above works fine but I also get an additional system-generated message
box telling me "The OpenReport action was cancelled."

The system generated message does not tell the user why the action was
cancelled. I want to use only my own message box and supress the system
generated message so the user doesn't have to respond to two message boxes.

Can this be done? If so how?
 
K

Ken Snell

You need to trap for Error Number 2501 in the code that opens the report. Do
you have an error handler in the code that is opening the report? If yes,
put this code in the error handler section:

If Err.Number <> 2501 Then MsgBox "Error has occurred"


If you're using On Error Resume Next in the code instead of an error
handler, put this line of code right after the OpenReport step:

If Err.Number <> 0 And Err.Number <> 2501 Then MsgBox "Error has occurred"
 
D

Dave

Thanks much Ken


Ken Snell said:
You need to trap for Error Number 2501 in the code that opens the report. Do
you have an error handler in the code that is opening the report? If yes,
put this code in the error handler section:

If Err.Number <> 2501 Then MsgBox "Error has occurred"


If you're using On Error Resume Next in the code instead of an error
handler, put this line of code right after the OpenReport step:

If Err.Number <> 0 And Err.Number <> 2501 Then MsgBox "Error has occurred"
 

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