TPL
06-09-2007, 06:54 AM
My process is running twice but it is not moving to the next record. I confess, I don't 'loop' very well. Any ideas? My record set is just two reports to start with:
rtReportstoPrintRepNumberReportNameRepDate1tCustomers6/1/20072tCustomersTest6/2/2007
It is running report 1 twice. . . . any help would be GREATLY appreciated. Thank you. I am trying to adapt Ken Puls excel pdfcreator code to access for outputting multiple reports with code. . .
Function ReportToPDFMultiple_Early()
'Author : Ken Puls ( )
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from )
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim sPrinterName As String
Dim sReportName As String
Dim lPrinters As Long
Dim lPrinterCurrent As Long
Dim lPrinterPDF As Long
Dim prtDefault As Printer
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strDate As String
Dim strRep As String
Dim strNum As Long
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("rtReportstoPrint")
strDate = MyRS!repdate
strRep = MyRS!reportname
strNum = MyRS!repnumber
'Resolve index number of printers to allow changing and preserving
sPrinterName = Application.Printer.DeviceName
On Error Resume Next
For lPrinters = 0 To Application.Printers.Count
Set Application.Printer = Application.Printers(lPrinters)
Set prtDefault = Application.Printer
Select Case prtDefault.DeviceName
Case Is = sPrinterName
lPrinterCurrent = lPrinters
Case Is = "PDFCreator"
lPrinterPDF = lPrinters
Case Else
'do nothing
End Select
Next lPrinters
On Error GoTo 0
'Change the default printer
Set Application.Printer = Application.Printers(lPrinterPDF)
Set prtDefault = Application.Printer
'Start PFF Creator
Set pdfjob = New PDFCreator.clsPDFCreator
sPDFPath = "C:\Documents and Settings\Tami-L4C\My Documents\backups"
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Function
End If
For strNum = 1 To 2
If strNum > 0 Then
With pdfjob
'/// Change the report and output file name here! ///
'sReportName = strRep
sPDFName = strRep & strDate & ".pdf"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
DoCmd.OpenReport (strRep)
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until the PDFCreator queue is clear
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
End If
Next strNum
pdfjob.cClose
'Reset the (original) default printer and release PDF Creator
Set Application.Printer = Application.Printers(lPrinterCurrent)
Set pdfjob = Nothing
End Function
Edited 12-Jun-07 by geekgirlau. Reason: insert vba tags
rtReportstoPrintRepNumberReportNameRepDate1tCustomers6/1/20072tCustomersTest6/2/2007
It is running report 1 twice. . . . any help would be GREATLY appreciated. Thank you. I am trying to adapt Ken Puls excel pdfcreator code to access for outputting multiple reports with code. . .
Function ReportToPDFMultiple_Early()
'Author : Ken Puls ( )
'Macro Purpose: Print to PDF file using PDFCreator
' (Download from )
' Designed for early bind, set reference to PDFCreator
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim sPrinterName As String
Dim sReportName As String
Dim lPrinters As Long
Dim lPrinterCurrent As Long
Dim lPrinterPDF As Long
Dim prtDefault As Printer
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Dim strDate As String
Dim strRep As String
Dim strNum As Long
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("rtReportstoPrint")
strDate = MyRS!repdate
strRep = MyRS!reportname
strNum = MyRS!repnumber
'Resolve index number of printers to allow changing and preserving
sPrinterName = Application.Printer.DeviceName
On Error Resume Next
For lPrinters = 0 To Application.Printers.Count
Set Application.Printer = Application.Printers(lPrinters)
Set prtDefault = Application.Printer
Select Case prtDefault.DeviceName
Case Is = sPrinterName
lPrinterCurrent = lPrinters
Case Is = "PDFCreator"
lPrinterPDF = lPrinters
Case Else
'do nothing
End Select
Next lPrinters
On Error GoTo 0
'Change the default printer
Set Application.Printer = Application.Printers(lPrinterPDF)
Set prtDefault = Application.Printer
'Start PFF Creator
Set pdfjob = New PDFCreator.clsPDFCreator
sPDFPath = "C:\Documents and Settings\Tami-L4C\My Documents\backups"
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Function
End If
For strNum = 1 To 2
If strNum > 0 Then
With pdfjob
'/// Change the report and output file name here! ///
'sReportName = strRep
sPDFName = strRep & strDate & ".pdf"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Print the document to PDF
DoCmd.OpenReport (strRep)
'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
DoEvents
Loop
pdfjob.cPrinterStop = False
'Wait until the PDFCreator queue is clear
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop
End If
Next strNum
pdfjob.cClose
'Reset the (original) default printer and release PDF Creator
Set Application.Printer = Application.Printers(lPrinterCurrent)
Set pdfjob = Nothing
End Function
Edited 12-Jun-07 by geekgirlau. Reason: insert vba tags