Solved

Cancel Access Report Print When No Data Exists

Posted on 2001-09-17
5
290 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

776 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