Solved

stop report opening if no data ACCESS 2010

Posted on 2014-09-10
4
788 Views
Last Modified: 2014-09-10
I have the message no data for report in the ON NO DATA event, but the report still opens.  How can I prevent the report opening when there is no data?

Sandra
0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 25

Expert Comment

by:chaau
ID: 40316060
You need to set the Cancel parameter to TRUE:
Private Sub Report_NoData(Cancel As Integer)
    ' display your custom message box here
    Cancel = True
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 40316110
You will also need to handle the error message your main application will get when the report fails to open.

I cannot remember what the error number is, but I just use a Resume Next after testing for that error.
0
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 40316115
If you open the report via VBA you need to handle this error:
On Error Resume Next
DoCmd.OpenReport "SomeReport", acViewPreview
If Err = 2501 Then Err.Clear

Open in new window

0
 

Author Closing Comment

by:ssmith94015
ID: 40316151
Thanks for the error handling code.  This worked perfectly.

Sandra
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question