views:

23

answers:

1

Hi, I have a macro that outputs a report to print. I dont want it to output if there are no records, because I dont want to waste paper. Please advise. I am familiar with Access, but do not know VBA. thank you very much, Nathaniel

+3  A: 

Use the reports On No Data event to display a message and then quit. This can be done using Macros. Start at the reports property sheet and click on the Event tab.

Tony Toews
Keep in mind that if the NoData event triggers and cancels the report printing, it will raise an error in the DoCmd.OpenReport line that opened the report. I use an OpenReport() function wrapper that traps and ignores the error generated in that case (Error 2501).
David-W-Fenton
David, good point. I'd forgotten about that. But if he runs the report from a macro what then? I've never done that.
Tony Toews
If you open the report with a macro and cancel it with the NoData event, it will give you the dreaded macro HALT error message. Now, with A2007, maybe the added error handling in macros makes it possible to avoid that. Certainly I expect it to be possible to handle the error in the new A2010 macros.
David-W-Fenton
Jeff O
GunnessFan. Thanks. But it also helps that David and I have known each other online for well over a decade now. Although I don't think we've ever actually talked via voice.
Tony Toews