OnNoData with Reports

itsmarkdavies

Registered User.
Local time
Today, 00:33
Joined
Jul 18, 2001
Messages
14
Can anyone tell me the best way to cancel the previewing of a report if it has no data in it ?. I have tried DoCmd.CancelEvent, but this produces a "runtime error 2501" and a mesasge saying that "the OpenReport action has been cancelled". Any help greatly appreciated. Thanks.
 
In the On No Data event of the report enter Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data to be printed in this report."
Cancel = True
End Sub
 
I can't get this to work? Any ideas?
 
I`ve sussed this now. Try the following, it`s a bit long winded, but it works.

In the REPORT (OnNoData event):-
=================================

Private Sub Report_NoData(Cancel As Integer)

Cancel = True
MsgBox "There is no data for this report.", 64,
"Information."

End Sub

On the FORM (Button or whatever) that opens the Report(s) :-
=============================================================

Private Sub cmdPreviewReports_Click()

On Error GoTo NoData

DoCmd.OpenReport "Report1", acViewPreview
DoCmd.OpenReport "Report2", acViewPreview
DoCmd.OpenReport "Report3", acViewPreview

NoData:

If Err.Number = 2501 Then
Resume Next
End If

End Sub


Hope this helps,

Mark Davies

itsmarkdavies@hotmail.com
 
Thank you

It's been over seven years since this post but Google found it and it solved my problem. thanks.:)
 

Users who are viewing this thread

Back
Top Bottom