Cancel printing if NoData

S

s4

Hi,
I have a few reports for printing.
I've put in the onevent for nodata to display a msgbox saying so, however
the report still prints. Is there a way to cancel the printing from the
nodata event?
Thanks
 
F

fredg

Hi,
I have a few reports for printing.
I've put in the onevent for nodata to display a msgbox saying so, however
the report still prints. Is there a way to cancel the printing from the
nodata event?
Thanks

The OnNoData event has a Cancel argument. That's what it's for.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data in report"
Cancel = True
End Sub

If you opened to report using code from an event on a form, this will
raise an error, so you need to trap the error in the event that opened
the report:

On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acViewPreview

Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_This_Sub
 
K

Kevin B

Use the report's On No Data event to control what happens when there isn't
any data.

With the report object selected, open the properties window and click on the
EVENT tab. Locate the On No Data event and create an Event Procedure similar
to the sample below.

The following example will display a messge and cancel the reporting process

Private Sub Report_NoData(Cancel As Integer)

MsgBox "There isn't any data to print."
Cancel = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top