Don't want to print report (1 Viewer)

MICHELE

Registered User.
Local time
Today, 08:25
Joined
Jul 6, 2000
Messages
117
I am trying write some code to print some reports, but only those that have data in them.
I have used DLookup before but that doesn't seem to work this time.
I have also been trying to use the On no data event on my report. What code would I write in that ?
 

madhouse

Registered User.
Local time
Today, 08:25
Joined
Jul 3, 2002
Messages
65
I don't know what method your using to populate the report with records from a table, but I find the following the easiest method when I don't want a report printed that doesn't contain any data:

1) Use SQL to place the records that are to be reported into a temporary table.

2) Use DCount to see if any records exist in the table, if they don't, display a message to say no data exists, else open the report for printing e.g.

If DCount("*", "tblTempReport") = 0 Then
MsgBox "The report has no data.", vbInformation, "No Data"
Exit Sub

Else

DoCmd.OpenReport "RptListLib", acViewNormal

End If


Hope that helps.
 
R

Rich

Guest
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There is no data for the period you have selected", vbOKOnly

Cancel = True

End Sub
 

Users who are viewing this thread

Top Bottom