Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use DoCmd.OutputTo acOutputReport to stop 2501 errors

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
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.

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.
 
You would need to add code in the CmdPrintFullNutriPlan_Click procedure to trap for err.number 2501. I expect you simply want the code to resume next if the error is encounter or maybe add a record to a log table.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top