View Full Version : calceling a report


dott
06-30-2003, 09:13 AM
I am trying to use either cancel = true or docmd.cancelevent to stop the printing of a report when there is no data

however, it comes up with the error:

2501 The OpenReport action was canceled.

Is there anyway around this inane error?

i tried docmd.setwarnings = false but it still came up

Rich
06-30-2003, 09:38 AM
Search here for 2501, it's been answered on numerous posts

daveUK
07-01-2003, 10:52 AM
You need to trap the error on the click event of the cmdbutton that opens the report.

i.e.

Private Sub CmdSearch_Click()
On Error GoTo Err_CmdSearch_Click

DoCmd.OpenReport "ReportName", acViewPreview


Exit_CmdSearch_Click:
Exit Sub

Err_CmdSearch_Click:

If Err = 2501 Then
MsgBox "There are no records for this date", vbExclamation, "No Data"
Else
MsgBox Err.Description
Resume Exit_CmdSearch_Click
End If

End Sub

HTH
Dave