no data - open report error (1 Viewer)

pascal

isolation
Local time
Today, 02:40
Joined
Feb 21, 2002
Messages
62
When I open a report with no data my own message box (put in the Report-NoData event) is shown followed by the following error: Runtime-error 2501 - The Openreport action was canceled. The report is opened by pushing on a button on a form with the following code: DoCmd.OpenReport "MyReport", acViewPreview (put in the On-Click event of the button). What am I doing wrong here. Can someone help me with this.
Thank you in advance.
 

Carol

Registered User.
Local time
Today, 02:40
Joined
Jan 15, 2000
Messages
280
Use the following and modify it to suit your report:



Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Err_Report_NoData

MsgBox "There are no absences for this employee for the year selected. Personnel Manager will cancel printing", vbInformation, "PRINTING"
Cancel = True

Exit_Report_NoData:
Exit Sub

Err_Report_NoData:
MsgBox Err.description, , "PRINTING"
Resume Exit_Report_NoData
End Sub
 

pascal

isolation
Local time
Today, 02:40
Joined
Feb 21, 2002
Messages
62
Thanks for the quick reply Carol but I'm afraid I still get the openreport error.
 

Carol

Registered User.
Local time
Today, 02:40
Joined
Jan 15, 2000
Messages
280
The above code should go on the report in the "On No Data" properties line.

The code behind your button on your form should be something like this:

Private Sub Report_Click()
On Error GoTo Err_Report_Click

Dim stDocName As String

stDocName = "AbsenceInformationLog"
DoCmd.OpenReport stDocName, acPreview

Exit_Report_Click:
Exit Sub

Err_Report_Click:
MsgBox Err.description
Resume Exit_Report_Click

End Sub
 

pascal

isolation
Local time
Today, 02:40
Joined
Feb 21, 2002
Messages
62
OK. That's it Carol. It works fine now. Thanks again.
 

Users who are viewing this thread

Top Bottom