Run-time error 2501 when opening a report

J

JimP

When setting the "On No Data" event to "Cancel = True" a report does not
open, unless..

The report is opened using a DoCmd.OpenReport. In this case a runtime error
2501 is triggered.

How can I prevent a report from opening when there is no data, and when
using DoCmd.OpenReport to open a report?
 
M

Marshall Barton

JimP said:
When setting the "On No Data" event to "Cancel = True" a report does not
open, unless..

The report is opened using a DoCmd.OpenReport. In this case a runtime error
2501 is triggered.

How can I prevent a report from opening when there is no data, and when
using DoCmd.OpenReport to open a report?


The cancel is reported back to the procedure that tried to
open the report so that procedure needs to trap that error
and ignore it.

One way this could be done is:

On Error GoTo ErrHandler
. . .
DoCmd.OpenReport . . .
. . .
AllDone:
Exit Sub

ErrHandler:
Select Case Err.Number
Case 2501
Resume AllDone
Case Else
MsgBox Err.Number & " - " & Err.Description
Resume AllDone
End Select
End 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