Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close report on NoData

Status
Not open for further replies.

g3a3n3n3

Technical User
Aug 6, 2003
43
AU
I have a report that gets it's data from a query. The criteria for this query is specified in a form. When there is no data in the report as a result of the criteria given I would like the report to close and not run.

To do this I put this code in

Private Sub Report_Open(Cancel As Integer)
On Error Resume Next
DoCmd.OpenReport "Rpt_HoursOfClientActivitybyOrganisation"
If Err.Number <> 0 Then If Err.Number <> 2501 Then MsgBox Err.Number & vbNewLine & Err.Description
On Error GoTo 0
End Sub



Theres two things that are going wrong
1. As soon as I click the OK button on the form after entering the criteria - the report prints out!!!
2. I get an error when there is no data.

Are they two seperate errors or do they have something to do with each other?!?!?!

Thanks in advance
Gillian [pc2]
 
1) If you want to preview the report on screen, use acViewPreview as the second parameter on the DoCmd.OpenReport call. By default (i.e. if not specified otherwise) it will use acViewNormal which will print directly to the printer.
2) Use the Report_NoData event - this includes a Cancel parameter that you can set. It will raise an error if you cancel the print like this, but you have On Error Resume Next (i.e. ignore all errors) in your calling code.

Private Sub Report_NoData(Cancel As Integer)
MsgBox &quot;There is no data to print&quot;
Cancel = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top