The OpenReport action was canceled.

  • Thread starter Steven M. Britton
  • Start date
S

Steven M. Britton

I have in the OnNoData event of my report a MsgBox that
tells the user why there is no data and what to do to fix
it.

But after the click OK, I get the system msgbox
saying "The OpenReport action was canceled." - Can someone
please remind me how to supress this message...

-Steve
 
R

Roger Carlson

You have to trap for the 2501 error in the code that calls the report. For
example:

Private Sub cmdPreview_Click()
On Error GoTo Err_cmdPreview_Click

Dim stDocName As String

stDocName = "rptGLTable"
DoCmd.OpenReport stDocName, acPreview

Exit_cmdPreview_Click:
Exit Sub

Err_cmdPreview_Click:
If Err.Number = 2501 Then
Resume Next
Else
MsgBox Err.Description
Resume Exit_cmdPreview_Click
End If

End Sub

The "If Err.Number =2501" section does the trick.
 
F

fredg

I have in the OnNoData event of my report a MsgBox that
tells the user why there is no data and what to do to fix
it.

But after the click OK, I get the system msgbox
saying "The OpenReport action was canceled." - Can someone
please remind me how to supress this message...

-Steve

The error message is coming from the code that was used to open the
report in the first place (probably a Form's command button click
event).
Trap the error in that 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
 

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