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!

Suppress Report

Status
Not open for further replies.

pleasehelpalot

Instructor
Oct 4, 2005
92
US
I have three reports that print from a command button. The reports are based on queriesthat may pull up multiple records. If the query does not pull up any records because none meet the indicated parameters, I don't want that report to print. What method would best accomplish this?
 
You could consider the No Data event of the report.
 
And this top secret line of code for it:

Code:
Cancel = True

Don't tell anyone else......

[wink]

"Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes."
 
I wanted to evaluate and run three reports consecutively. Using this method caused a runtime message to appear which said I cancelled the event. This prevented the running of the other two reports. I had to seperate the command buttons into one for each report and add a DoCmd.openreport statement on each NoData event which prevented the runcode message from appearing. This solution was not as efficient, but it works.
 
Glad to hear you found success! If you're interested, I recall a method of the DoCmd object called SetWarnings On/Off that may or may not be of help. I've never used it, but possibly it might suppress the message boxes for null reports. A quick check in Access help will tell for sure.

"Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes."
 
You need to capture the cancel error:

Code:
Sub OutputCancelledByUser()
On Error GoTo Error_MySub

<...>

Error_MySub:
Select Case Err.Number
Case 2501
    MsgBox "Output cancelled by user"
Case Else
    MsgBox Err.Description
End Select

End Sub

You could also use Resume Next and check for the same error. Finally, you could use DCount to test if the report recordset returns records, and only open the report if it does.
 
Nice call, Remou!

"Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top