473,395 Members | 2,446 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,395 software developers and data experts.

nodata event / still printing form data

I have a report that I run from a Macro. This macro executes when you click the printer icon button on the form. The macro is simple: 1. open report 2. printout 3. close report . All this works fine - except when I do not want to print the report if no data exist. I have the nodata event with cancel = true. It works but, a print is generated that looks like a snapshot of the form with the printer icon with the 2 test records. Why is that printing? How can I get rid of it? Thanks in advance.

The report has this event procedure:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_NoData(Cancel As Integer)
  2. Cancel = True
  3. '
  4. MsgBox ("report cancelled")
  5. End Sub
Feb 26 '09 #1
4 1851
DonRayner
489 Expert 256MB
Your problem is being caused because of the macro. The cancel event on the report doesn't stop the macro from running, it just stops the form from opening. The print command still runs and since the form is now active instead of the report it is printing the form.

Instead of using a Macro to print the report you need to open it directly from the command button that you click to print. Assuming your button is named print the vba for the on click event would be as follows. Just replace ReportName with the actual name of your report.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Click()
  2. On Error GoTo ErrPoint
  3. DoCmd.OpenReport "ReportName", acViewNormal
  4.  
  5. ExitPoint:
  6. Exit Sub
  7.  
  8. ErrPoint:
  9. If Err.Number = 2501 Then
  10.     MsgBox "Report Cancelled"
  11.     Resume ExitPoint
  12. Else
  13.     MsgBox Err.Number & " " & Err.Description
  14. End If
  15. End Sub
The cancel event generates error number 2501 that you can trap and use to display your message box.
Feb 26 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
Hi. I guess from what you say about the steps performed by your macro it opens the report in print preview mode, then uses printout as the next macro action. The cancel event will leave you with no report to print, as it closes the open report immediately (there being nothing to print preview).

If I am right about this you can instead send the report directly to print and take out your printout and close macro actions. The print and print preview options are under View in your open report macro action.

-Stewart
Feb 26 '09 #3
Don and Stewart - much thanks for your response. I have tried to like Macros but they can be a pain - like this example has shown. Here is the final solution taken from Don's code. There are actually 4 reports run at the same time, but only the 4th will have no data sometimes. A Query is done for reports 1-3 and another done for report 4 (which may have scanned documents or not). It was the ChemicalReport4ScanDoc that has the nodata event. So the final analysis is: the Macro was creating extra print after the report was cancelled with the nodata event.
Expand|Select|Wrap|Line Numbers
  1. Public Sub ChemicalPrintSub()
  2.     On Error GoTo ErrPoint
  3. '
  4. DoCmd.OpenReport "ChemicalReport1", acViewNormal
  5. DoCmd.OpenReport "ChemicalReport2", acViewNormal
  6. DoCmd.OpenReport "ChemicalReport3", acViewNormal
  7. DoCmd.OpenReport "ChemicalReport4ScanDoc", acViewNormal
  8. '
  9. ExitPoint:
  10. Exit Sub
  11.  
  12. ErrPoint:
  13. If Err.Number = 2501 Then
  14.     Resume ExitPoint
  15. Else
  16.     MsgBox Err.Number & " " & Err.Description
  17. End If
  18. '
  19. End Sub
Feb 26 '09 #4
DonRayner
489 Expert 256MB
You're quite welcome, good luck with your project.

Don
Feb 27 '09 #5

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

Similar topics

2
by: CSDunn | last post by:
Hello, I have an Access 2003 report that opens in print preview and then maximizes upon clicking a button from a form. The OnClick event of the button fires a macro to open the report. How can...
4
by: Richard Sherratt | last post by:
Access 97 and SQL Server 2000. Reports in this system are driven from a parameter form. Parameters are used to make a WHERE clause. If no parameters are selected, strWhere is a zero length...
1
by: Jimmy | last post by:
Is there a way to check if there are no records in a filtered form and display an error message such as can be done using the NoData event for a report?
15
by: sara | last post by:
I am stuck. I have a report that I use in multiple places, so I call it with varying parameters (using the Where Clause in the code). I preview the report, send it to snap, then close the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.