The OpenReport action was cancelled

  • Thread starter Thread starter Tony Wainwright
  • Start date Start date
T

Tony Wainwright

Hi guys

I have the following section in each of my reports to elegantly deal with no data situations

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data found! Closing report."
DoCmd.SetWarnings False
Cancel = True
DoCmd.SetWarnings True
End Sub

However after the 'No data found message' I get a message box with this message:
'The OpenReport action was cancelled.'

How do I stop this happening
Tony
 
Hi guys

I have the following section in each of my reports to elegantly deal with
no data situations

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data found! Closing report."
DoCmd.SetWarnings False
Cancel = True
DoCmd.SetWarnings True
End Sub

However after the 'No data found message' I get a message box with this
message:
'The OpenReport action was cancelled.'

How do I stop this happening

In the code that calls the report, you need to include an error handler and
the error handler needs to be configured to ignore error number 2501.

On Error GoTo ErrHandler

DoCmd.OpenReport blah blah...

Egress:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
'ignore
Case Else
(your standard error handling code)
End Select
Resume Egress
End Sub
 
You need to trap that error.
You can put On Error Resume Next and no msg will appear
or
On Error Errormsg and then have a section named

Errormsg: Msgbox "your own error here"
-----Original Message-----
Hi guys

I have the following section in each of my reports to
elegantly deal with no data situations
 
Back
Top