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

Report not to print if source query is empty

Status
Not open for further replies.

DBritter

Technical User
Jun 28, 2000
37
US
I have a series of mailmerge reports that run off of queries. I have a form set up to run all of the letters and their underlying queries when a button is clicked.

The problem occurs when the query comes up with no results and the letter prints anyways with "#error" in the place of the null fields.

I want to be able to print or not print based on wether there are any records in the query.
 
Find the recordcount of the query before you go to the print. If your button just does a doCmd for the report, you will need to add the steps to get the record count from the query before the docmd.

If MyQry.RecordCount > 0 then
[tab]DoCmd.OpenReport ...
End If

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Alternatively, you could simply place some code in the 'On No Data' event in the report that aborts the report by setting 'Cancel=True'. This way, you don't have to run the query more than once.
-Doug
 
Doug,

Yours is much better. I don't use Ms. Access much anymore, and I misplaced my memory for the NoMemory 'event'.

MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top