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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem: Report printing even if no records found. 1

Status
Not open for further replies.

Manny64

Technical User
May 1, 2001
16
0
0
CA
Hello all,

I have a Print button on a form that has an OnClick event:
DoCmd.OpenReport "ILP_017", acViewNormal
DoCmd.OpenReport "ILP_017a", acViewNormal
DoCmd.OpenReport "ILP_022", acViewNormal

Each report data source is an SQL query.

Problem:
When one of the queries returns zero records the report still prints blank with a number of #Errors in various fields.

Goal:
I just want reports to print when there are records returned by the query.

How do I accomplish this?

Thank you,
Manny64
 
I often use an If statement combined with a DCount on the click event to check the query supplying my report the data to see if there are any records and if there is not popup a MsgBox. Here's what the code like:

If DCount("[CustID]", "qselRAMSales") >=1 Then
DoCmd.OpenReport "ILP_017", acViewNormal
Else
MsgBox "No data to report on for ILP_017!"
End If


HTH Joe Miller
joe.miller@flotech.net
 
Sorry, forgot to change the field/table names in my last post:

If DCount("[UniqueID]", "MyQueryName") >=1 Then
DoCmd.OpenReport "ILP_017", acViewNormal
Else
MsgBox "No data to report on for ILP_017!"
End If Joe Miller
joe.miller@flotech.net
 
This is exactly what I needed.

Thank you, Joe,

Manny64
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top