Excel_Kid1081
Registered User.
- Local time
- Today, 12:38
- Joined
- Jun 24, 2008
- Messages
- 34
Hello-
I currently have the code below that loops through a table with named reports and prints them to PDF. The code works fine except each report is overwritten by the next report in the loop because all of the reports are being saved under the same name.
Sub LoopReports()
Dim db As Database
Dim strSQL As String
Dim rs As Recordset
Dim RName As Variant
'Adobe set-up
Dim tmpPrinter As Printer
Dim rptName As String
Set tmpPrinter = Application.Printer 'Default Printer
Set Application.Printer = Application.Printers("Adobe PDF") 'Changes to Adobe
Set rs = CurrentDb.OpenRecordset("SELECT Report_Name FROM tblReports")
Do Until rs.EOF
rptName = rs!Report_Name
DoCmd.SetWarnings False
DoCmd.OpenReport rptName, acViewNormal
DoCmd.Close acReport, rptName, acNo
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
Debug.Print strSQL
Set tmpPrinter = Application.Printer
Set Application.Printer = Application.Printers(0) ' Restore Default printers
End Sub
How would I alter this code to get each report in the loop to be saved separately with their own report names?
Thanks!
EK
I currently have the code below that loops through a table with named reports and prints them to PDF. The code works fine except each report is overwritten by the next report in the loop because all of the reports are being saved under the same name.
Sub LoopReports()
Dim db As Database
Dim strSQL As String
Dim rs As Recordset
Dim RName As Variant
'Adobe set-up
Dim tmpPrinter As Printer
Dim rptName As String
Set tmpPrinter = Application.Printer 'Default Printer
Set Application.Printer = Application.Printers("Adobe PDF") 'Changes to Adobe
Set rs = CurrentDb.OpenRecordset("SELECT Report_Name FROM tblReports")
Do Until rs.EOF
rptName = rs!Report_Name
DoCmd.SetWarnings False
DoCmd.OpenReport rptName, acViewNormal
DoCmd.Close acReport, rptName, acNo
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
Debug.Print strSQL
Set tmpPrinter = Application.Printer
Set Application.Printer = Application.Printers(0) ' Restore Default printers
End Sub
How would I alter this code to get each report in the loop to be saved separately with their own report names?
Thanks!
EK