I use the following code to send a number of reports to my printer. There are about 16 reports in total, I have reduced the code just to keep things simple.
I also use the following repeated code to send the same reports for PDF
Each report has the following code in NoData
When I send the reports to the printer if there is no data then I get a message box click OK and then a run time error 2501 the openreport action was cancelled error message.
If I send the reports to PDF and there is no data I get the message box click OK but no run time error message.
What is the easiest way to stop the 2501 error messages? Can I use DoCmd.OutputTo acOutputReport to send the report to the printer and would this stop the 2501 error?
Or is there an easier way to send groups of reports to a printer?
I hope this all makes sense and thank you for any input.
Code:
Private Sub CmdPrintFullNutriPlan_Click()
'Main Folder
'Soil Analysis Results for NutriPlan
DoCmd.OpenReport "rptSoilAnalRsltsForNutriPlan", acViewNormal
'N Max Field Limits (Report 1)
DoCmd.OpenReport "rptNMaxfieldlimits", acViewNormal
'N Max N From Manure Applications (Report 2)
DoCmd.OpenReport "rptCropNFromOMforNMaxCalcs", acViewNormal
'Fertiliser Requirement with Field Details
DoCmd.OpenReport "rptFertReqWithFieldDetail", acViewNormal
'Header
DoCmd.OpenReport "rptMainNPlanHeader", acViewNormal
DoEvents
MsgBox "Finished sending report to printer"
I also use the following repeated code to send the same reports for PDF
Code:
'Header
DoCmd.OutputTo acOutputReport, "rptMainNPlanHeader", "PDF Format (*.pdf)", "" _
& "x:\Nutrifocus\NutriPlan Holding Folder\" & Me.[AccountNameLbl] + (Format(Now(), " ddmmyy")) + " - " & "1 - Header.pdf"
'NUTRIPLAN
DoCmd.OutputTo acOutputReport, "rpt10-NutriPlan09", "PDF Format (*.pdf)", "" _
& "x:\Nutrifocus\NutriPlan Holding Folder\" & Me.[AccountNameLbl] + (Format(Now(), " ddmmyy")) + " - " & "2 - NUTRIPLAN.pdf"
Each report has the following code in NoData
Code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "There are currently no records available for this report."
Cancel = True
End Sub
When I send the reports to the printer if there is no data then I get a message box click OK and then a run time error 2501 the openreport action was cancelled error message.
If I send the reports to PDF and there is no data I get the message box click OK but no run time error message.
What is the easiest way to stop the 2501 error messages? Can I use DoCmd.OutputTo acOutputReport to send the report to the printer and would this stop the 2501 error?
Or is there an easier way to send groups of reports to a printer?
I hope this all makes sense and thank you for any input.