?
Solved

Cancel Access Report Print When No Data Exists

Posted on 2001-09-17
5
Medium Priority
?
324 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
[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
  • 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 1200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses

764 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