Dont print rpt if no data

  • Thread starter Thread starter Razor
  • Start date Start date
R

Razor

Hi,

I have a report that I am sending to the printer from a
form.

How do I make it such that the report does not print if
there is no data in it?

Currently, if there is no data, it prints a blank sheet
with #Error in controls that reference fields in the
recordsource, because the recordsource is empty.

Thanks!

Regards,
Razor
 
Code the Report's OnNoData event:
MsgBox "There are no records to print"
Cancel = True

You will get an error 2501 message.
Code the Form's Command Button (that you used to open the report) click
event:

On Error Goto Err_Handler
DoCmd.OpenReport "ReportName"
Exit_This_Sub:
Exit Sub
Err_Handler:
If err = 2501 then
Else
MsgBox "Error # & Err.Number
End If
Resume Exit_This_Sub
 
If the report's record source is a saved query then, in addition to Fred's
suggestion, you can simply count the number of records returned by the query:

If DCount("*","qryName") > 0 Then
'The report will contain data
Else
'No records returned
End If
 
Back
Top