Suppressing the "OpenReport Action was canceled" message

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

I have a MS Access database where I have the following
code entered in the "On NoData" event for a report:

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No Records Match the Criteria You Entered." &
(Chr(13)) & " As a result, the list or output you
requested is blank and won't be shown", vbOKOnly +
vbCritical, "Blank Report!"
Cancel = True
End Sub

I have a button on a form, when clicked, will open the
above report in preview mode. The code, as created by the
command button wizard is:

Private Sub Command128_Click()
On Error GoTo Err_Command128_Click

Dim stDocName As String

stDocName = "Year 6 Accepted"
DoCmd.OpenReport stDocName, acPreview

Exit_Command128_Click:
Exit Sub

Err_Command128_Click:
MsgBox Err.Description
Resume Exit_Command128_Click

End Sub


If I click the button and the report is blank, it displays
the message as programmed. However, after I click the OK
button, MS Access then displays its message: "The
OpenReport Action was cancelled."

How can I suppress this second message from Access?

Any advice appreciated.

Andrew
 
Trap the error:

Private Sub Command128_Click()
On Error GoTo Err_Command128_Click
Dim stDocName As String

stDocName = "Year 6 Accepted"
DoCmd.OpenReport stDocName, acViewPreview

Exit_Command128_Click:
Exit Sub

Err_Command128_Click:
If Err.Number <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_Command128_Click
End Sub
 
Back
Top