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!

"Runtime error 2501-The open report was cancelled"

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I have the following code which works fine on my machine which has SP2 and SP3 (Office 2007) installed.

However, another user is getting the error "Runtime error 2501-The open report was cancelled" when trying to run any reports.

Do they need SP3 installed as well as SP2. They have SP2 installed

Code:
Private Sub btnSubmit_Click()
On Error GoTo Err_handler

Dim ReportLocation As String
Dim strLocation As String
ReportLocation = DMax("ReportLocation", "tblReportLocation")
strLocation = ReportLocation
    
    If IsNull(Me.cboReports) Then
    MsgBox "You must select a report"
        Else
            If Me.cboReports = 1 Then
            DoCmd.OutputTo acOutputReport, "rptProspecttoClientForecast", acFormatPDF, strLocation & "ProspecttoClientForecastReport.pdf", True
                Else
                    If Me.cboReports = 2 Then
                    DoCmd.OutputTo acOutputReport, "rptLengthofAcquisition", acFormatPDF, strLocation & "LengthofAcquisitionReport.pdf", True
                        Else
                            If Me.cboReports = 3 Then
                            DoCmd.OutputTo acOutputReport, "rptNumberofMeetings", acFormatPDF, strLocation & "NumberofMeetings.pdf", True
                                Else
                                    If Me.cboReports = 4 Then
                                    DoCmd.OutputTo acOutputReport, "rptCategoriesSignedatLOE", acFormatPDF, strLocation & "CategoriesSignedatLOE.pdf", True
                                        Else
                                            If Me.cboReports = 5 Then
                                            DoCmd.OutputTo acOutputReport, "rptCategoriesSignedRecReport", acFormatPDF, strLocation & "CategoriesSignedRecReport.pdf", True
                                                Else
                                                    If Me.cboReports = 6 Then
                                                    DoCmd.OutputTo acOutputReport, "rptLengthofDelivery", acFormatPDF, strLocation & "LengthofDelivery.pdf", True
                                                    End If
                                            End If
                                    
                                    End If
                            End If
                    End If
            
            End If
    End If
    
Endit:
Exit Sub

Err_handler:
If Err = 2501 Then
Resume Endit
Else
MsgBox _
"An unexpected error has been detected" & Chr(13) & _
"Description is: " & Err.Number & ", " & Err.Description & Chr(13) & _
"Module is: commandbutton_click" & Chr(13) & _
"Please note the above details before contacting support"
Resume Endit
End If
Exit Sub
End Sub

It is breaking on the line DoCmd... for each report.

Report location value on their machine is "D:\Reports". I have checked that the folder exists and they have write access to it.

 
Does the other computer have a default printer defined in the control panel?

I would actually set the Row Source of the combo box to a table containing the actual report name and file name. This would reduce a ton of your code to:
Code:
    Else
       strRptName = Me.cboReports.Column(x)
       strFileName = Me.cboReports.Column(y)
       DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, strLocation & strFileName, True
Minimally change your code to something more readable:
Code:
Private Sub btnSubmit_Click()
	On Error GoTo Err_handler

	Dim ReportLocation As String
	Dim strLocation As String
	Dim strRptName as String
	Dim strFileName as String
	ReportLocation = DMax("ReportLocation", "tblReportLocation")
	strLocation = ReportLocation
    
    If IsNull(Me.cboReports) Then
		MsgBox "You must select a report"
      Else
		Select Case Me.cboReports
			Case 1 
				strRptName = "rptProspecttoClientForecast"
				strFileName = "ProspecttoClientForecastReport.pdf"
			Case 2
				strRptName = "rptLengthofAcquisition"
				strFileName = "LengthofAcquisitionReport.pdf"
			Case 3
				strRptName = "rptNumberofMeetings"
				strFileName = "NumberofMeetings.pdf"
			Case 4
				strRptName = "rptCategoriesSignedatLOE"
				strFileName = "CategoriesSignedatLOE.pdf"
			Case 5
				strRptName = "rptCategoriesSignedRecReport"
				strFileName = "CategoriesSignedRecReport.pdf"
			Case 6
				strRptName = "rptLengthofDelivery"
				strFileName = "LengthofDelivery.pdf"
		End Select
		DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, strLocation & strFileName, True
    End If
    
Endit:
	Exit Sub

Err_handler:
	If Err = 2501 Then
		Resume Endit
	 Else
		MsgBox _
		"An unexpected error has been detected" & Chr(13) & _
		"Description is: " & Err.Number & ", " & Err.Description & Chr(13) & _
		"Module is: commandbutton_click" & Chr(13) & _
		"Please note the above details before contacting support"
		Resume Endit
	End If
	Exit Sub
End Sub

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top