Home  |   French  |   About  |   Search  | mvps.org  

What's New
Table Of Contents
Credits
Netiquette
10 Commandments 
Bugs
Tables
Queries
Forms
Reports
Modules
APIs
Strings
Date/Time
General
Downloads
Resources
Search
Feedback
mvps.org

In Memoriam

Terms of Use


VB Petition

Reports: Close report automatically if no data found

Author(s)
Dev Ashish

(Q)    How can I close a report automatically if there's no data returned by the underlying query?

(A)    You can use the Report's OnNoData event for this.  For example, the following code

'************* Code Start *************
Private Sub Report_NoData(Cancel As Integer)
    MsgBox "No data found! Closing report."
    Cancel = True
End Sub
'************* Code End *************

    will automatically close the report if there are no records in the underlying source.

    However, if you're opening the report from code behind a form,   you need to handle the error that's generated as a result.

'*********** Code Start ************
Private Sub TestNoData_Click()
    On Error Resume Next
    DoCmd.OpenReport "SomeReport", acViewPreview
    If Err = 2501 Then Err.Clear
End Sub
'*********** Code End   ************

© 1998-2010, Dev Ashish & Arvin Meyer, All rights reserved. Optimized for Microsoft Internet Explorer