Supress Message

  • Thread starter Thread starter Dave
  • Start date Start date
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?
 
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"
 
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"
 
Back
Top