Microsoft

How to close an Access report automatically when there's no data to report

An Access report with no data has no purpose and confuses users. When an Access report has no data to report, circumvent it and display a message that tells users why you're doing so.

Reports display data in a meaningful fashion, unless there's no data to report. When this happens, you'll want to usurp the reporting process a bit to avoid confusion. That's accomplished easily enough using the report's No Data event. Simply open the report's module and enter the following event procedure: Private Sub Report_NoData(Cancel As Integer) MsgBox "There's no data to report.", vbOKOnly, "Error" Cancel = True End Sub Be sure to save the form after adding the code. When users open the report with no data to report, Access will display a meaningful message. (You can use whatever message you like, of course.) Users don't accidentally print useless reports or call you in a panic wanting to know what's wrong with the report.

About Susan Harkins

Susan Sales Harkins is an IT consultant, specializing in desktop solutions. Previously, she was editor in chief for The Cobb Group, the world's largest publisher of technical journals.

Editor's Picks

Free Newsletters, In your Inbox