Solved

stop report opening if no data ACCESS 2010

Posted on 2014-09-10
4
686 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
  • 2
4 Comments
 
LVL 24

Expert Comment

by:chaau
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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 24

Accepted Solution

by:
chaau earned 500 total points
Comment Utility
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
Comment Utility
Thanks for the error handling code.  This worked perfectly.

Sandra
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now