473,396 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Print another report on a OnNoData event

Hi

I currently have the following code attached to a command button on a switchboard form. This is basic Access 2000.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_daily_reports_button_Click()
  2.  
  3. On Error GoTo NoData
  4.  
  5.     DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
  6.     DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
  7.     DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
  8.     DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
  9.     DoCmd.OpenReport "FIMs issued (today)", acViewNormal
  10.  
  11. NoData:
  12.  
  13. If Err.Number = 2501 Then
  14. Resume Next
  15. End If
  16.  
  17. End Sub
For the first 2 reports, I have another report that will just print a separate report when there are no items to report. I am trying to work out the code needed.

I have tried setting on the report's NoData event to print the other report but the macro stops. Is there a way to refer to the NoData event in the code builder as above?

Prior to the above code builder I have also tried a macro to print all the same reports with a separate macro in the sales return report on the nodata event but that comes with the error "The function Open Report is not available now".

Any ideas will be greatly appreciated.

Thanks
Mar 21 '07 #1
2 2822
nico5038
3,080 Expert 2GB
You should check the report's query to return records before triggering the report.

One way is to use a recordset for this, but as I guess you only need to check a specific date, the DLOOKUP() could be an alternative like:
Expand|Select|Wrap|Line Numbers
  1. IF IsNull(DLOOKUP("datefieldname","tablename","datefield=Date()")) then
  2.  
  3. else
  4.  
  5. endif
  6.  
Dlookup() will return Null when nothing is found.

Clear ?

Nic;o)
Mar 25 '07 #2
ADezii
8,834 Expert 8TB
Hi

I currently have the following code attached to a command button on a switchboard form. This is basic Access 2000.

Private Sub Print_daily_reports_button_Click()

On Error GoTo NoData

DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
DoCmd.OpenReport "FIMs issued (today)", acViewNormal

NoData:

If Err.Number = 2501 Then
Resume Next
End If

End Sub

For the first 2 reports, I have another report that will just print a separate report when there are no items to report. I am trying to work out the code needed.

I have tried setting on the report's NoData event to print the other report but the macro stops. Is there a way to refer to the NoData event in the code builder as above?

Prior to the above code builder I have also tried a macro to print all the same reports with a separate macro in the sales return report on the nodata event but that comes with the error "The function Open Report is not available now".

Any ideas will be greatly appreciated.

Thanks
Nico has the right idea, just substitute you own Parameters:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_daily_reports_button_Click()
  2. On Error GoTo NoData
  3.  
  4. If IsNull(DLookup("datefieldname", "tablename", "datefield=Date()")) Then
  5.   'Print Report for no Data
  6. Else
  7.   DoCmd.OpenReport "Sales Return (TODAY)", acViewNormal
  8. End If
  9.  
  10. If IsNull(DLookup("datefieldname", "tablename", "datefield=Date()")) Then
  11.   'Print Report for no Data
  12. Else
  13.   DoCmd.OpenReport "Sales/Collections (TODAY)", acViewNormal
  14. End If
  15.  
  16. DoCmd.OpenReport "SRV Register (TODAY)", acViewNormal
  17. DoCmd.OpenReport "STPC Voucher Register (TODAY)", acViewNormal
  18. DoCmd.OpenReport "FIMs issued (today)", acViewNormal
  19.  
  20. NoData:
  21.  
  22. If Err.Number = 2501 Then
  23.   Resume Next
  24. End If
  25. End Sub
Mar 25 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Michael Dekson | last post by:
Access 97. I make a report and I want first to see report and then print report without type CONTROL + P. Can I make some button or can I see print button in toolbar meny. Thanks
2
by: ChadDiesel | last post by:
Hello, I have a form and subform with their tables linked by a field called Load_ID. I have a button on my subform that prints just the items listed on that particular subform (looking at...
0
by: Joki | last post by:
Hi, All Can i capture print button click event on crystalreportview control? Thanx Joki
5
by: Tony Dong | last post by:
Hi there, I am newer for dot net I want to make a report and then print it, the report may include images and text, how can I do that, any one can give me a suggestion? I know how to...
1
by: thh108688 | last post by:
Hi All, Is anyone know how to do a print report based on my current record. What i would like to get is once i have entered all the value in the form, when i hit the print button, all the value...
2
by: felicia | last post by:
Can anyone help me on How to use Data Report in VB and how to print report? I hope i can generate the Data Report without Data Environment because I am not fammiliar with it. Simple adodb or adodc...
10
by: Snoopy33 | last post by:
I have a DB that I developed on access XP (2002) and deployed over a year ago. No one has had problems printing any of the reports within the DB until we started loading 2007 on new computers. ...
0
by: Fred Zuckerman | last post by:
Hi All, I have a report with an accumulating value control. I use the Detail_Format event to periodically change the backcolor of the control. The control (Me.Tot) prints green except for the...
1
by: abil | last post by:
i've already build a program that contain all the price, the change given back to the customer but i dun have no idea which function i should use to do program print report... #include <cstdlib>...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.