calceling a report

dott

Registered User.
Local time
Today, 09:32
Joined
Jun 24, 2003
Messages
56
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
 
Try this

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
 

Users who are viewing this thread

Back
Top Bottom