[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cancel Access Report Print When No Data Exists

Posted on 2001-09-17
5
Medium Priority
?
335 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

656 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