Solved

Cancel Access Report Print When No Data Exists

Posted on 2001-09-17
5
267 Views
Last Modified: 2012-08-14
I am printing multiple reports (8) from a Command Button using DoCmd.OpenReport for each report, however, all forms are not always required.  I've tried entering "Cancel = True" on the "ON NODATA" event of the report but I always get an error message when the "ON NODATA" event is used.  Is there some other way I can stop printing the blank reports when no data is available for that report?
0
Comment
Question by:mfuller
  • 3
5 Comments
 
LVL 8

Expert Comment

by:dovholuk
ID: 6488791
in the on nodata event use:

On Error resume next

and your problem should be solved...

dovholuk
0
 
LVL 8

Expert Comment

by:dovholuk
ID: 6488797
pardon me... i mean behind the command button use On Error Resume Next...

sorry bout that...

dovholuk
0
 
LVL 8

Accepted Solution

by:
dovholuk earned 300 total points
ID: 6488808
let me clarify... you STILL need the Cancel = True statement in the on NoData event and before you open the report you need a On Error Resume Next. In the NoData event, i usually put a message box stating "No Data found", but that's up to you.

here's a sample command button...

Private Sub cmdOpenReport_Click()

   On Error Resume Next

DoCmd.OpenReport "YourReportNameHere", acViewPreview
 
End Sub

hope that clears it up. sorry for the multiple posting...

dovholuk
0
 
LVL 6

Expert Comment

by:Mach1pro
ID: 6488825
Leave the Cancel = True in the  OnNOData  event of the report. Then in the form that calls the event, (probably a button OnClick event) add error handling there. It should look something like this

Private Sub cmdMyReport_Click()
On Error GoTo err_MyReport

DoCmd.OpenReport "MyReport


ExitSub:
    Exit Sub

err_MyReport:
     If Err.Number = 2501 Then   ' no data
        Resume ExitSub
    Else
       MsgBox Err.Number & "  " & Err.Description
      Resume ExitSub
   End If
0
 

Author Comment

by:mfuller
ID: 6488855
Thanks!  It worked like a champ!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now