Run-time error 2501 when opening a report

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