justin198z28
New member
- Local time
- Today, 00:14
- Joined
- Sep 30, 2011
- Messages
- 4
Hi!
I'm struggling with a vb macro in access 2007 that returns a "runtime error 2501 outputto action was cancelled". The codes is intended to break up a 1690 page report into 338 five page pdfs, name them, and save in a file structure it creates. Unfortunately it errors when it finishes creating the first pdf - the debugger highlights the DoCmd.OutputTo acOutputReport line.
I've tried different computers and uninstalling/reinstalling printer drivers. I've added error handling to ignore error 2501 but the code then runs but the pdfs and folder structure is never produced. This code worked the last time the report was run a year ago. I've inherited this project from someone who left the company and I have to admit I have almost no knowledge of vb code. Any idea what the problem is?
Option Compare Database
Option Explicit
Private Sub CreateReports_Click()
Dim cn As ADODB.Connection
Dim rsDistricts As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rsDistricts = cn.Execute("SELECT [District_Code], [AGENCY_KEY], [AGENCY_NAME] FROM District_List")
Do Until rsDistricts.EOF
'Open report for a specific district
DoCmd.OpenReport "JUSTIN_District_Report_Template for 2010-11 9-27", acViewPreview, , "[District_Code]='" & _
rsDistricts![District_Code] & "'", acWindowNormal
'Output report to pdf file
DoCmd.OutputTo acOutputReport, "JUSTIN_District_Report_Template for 2010-11 9-27", acFormatPDF, _
"G:\OEA\TSH\ACCESS for ELLs Data\SecureReports\AMAO Reports\" & rsDistricts![AGENCY_KEY] & "\999999\2010_11\" & rsDistricts![AGENCY_NAME] & "_" & rsDistricts![District_Code] & "_ELL_AMAO_2010-11.pdf", , , , acExportQualityPrint
'Close report
DoCmd.Close acReport, "JUSTIN_District_Report_Template for 2010-11 9-27"
rsDistricts.MoveNext
Loop
cn.Close
End Sub
I'm struggling with a vb macro in access 2007 that returns a "runtime error 2501 outputto action was cancelled". The codes is intended to break up a 1690 page report into 338 five page pdfs, name them, and save in a file structure it creates. Unfortunately it errors when it finishes creating the first pdf - the debugger highlights the DoCmd.OutputTo acOutputReport line.
I've tried different computers and uninstalling/reinstalling printer drivers. I've added error handling to ignore error 2501 but the code then runs but the pdfs and folder structure is never produced. This code worked the last time the report was run a year ago. I've inherited this project from someone who left the company and I have to admit I have almost no knowledge of vb code. Any idea what the problem is?
Option Compare Database
Option Explicit
Private Sub CreateReports_Click()
Dim cn As ADODB.Connection
Dim rsDistricts As ADODB.Recordset
Set cn = CurrentProject.Connection
Set rsDistricts = cn.Execute("SELECT [District_Code], [AGENCY_KEY], [AGENCY_NAME] FROM District_List")
Do Until rsDistricts.EOF
'Open report for a specific district
DoCmd.OpenReport "JUSTIN_District_Report_Template for 2010-11 9-27", acViewPreview, , "[District_Code]='" & _
rsDistricts![District_Code] & "'", acWindowNormal
'Output report to pdf file
DoCmd.OutputTo acOutputReport, "JUSTIN_District_Report_Template for 2010-11 9-27", acFormatPDF, _
"G:\OEA\TSH\ACCESS for ELLs Data\SecureReports\AMAO Reports\" & rsDistricts![AGENCY_KEY] & "\999999\2010_11\" & rsDistricts![AGENCY_NAME] & "_" & rsDistricts![District_Code] & "_ELL_AMAO_2010-11.pdf", , , , acExportQualityPrint
'Close report
DoCmd.Close acReport, "JUSTIN_District_Report_Template for 2010-11 9-27"
rsDistricts.MoveNext
Loop
cn.Close
End Sub