Solved

Cancel Access Report Print When No Data Exists

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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