I am trying to combine multiple access reports in one PDF using pdfcreator, however it doesn't work for me...
Can you please check the following code:
Expand|Select|Wrap|Line Numbers
- Sub PrintAccessReportToPDF_Early()
- 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 sReportName1 As String
- '/// Change the report and output file name here! ///
- sReportName = "rpt_Employee"
- sReportName1 = "rpt_Employee_1"
- sPDFName = "EmployeeList_" & Format(Date, "yyyymmdd") & ".pdf"
- sPDFPath = "C:\Local\Data\mr97856\Reports\" 'EmployeeList_" & Format(Date, "yyyymmdd")
- '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
- With pdfjob
- If .cStart("/NoProcessingAtStartup") = False Then
- MsgBox "Can't initialize PDFCreator.", vbCritical + _
- vbOKOnly, "PrtPDFCreator"
- Exit Sub
- End If
- .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 (sReportName)
- DoCmd.OpenReport (sReportName1)
- 'Wait until the print job has entered the print queue
- Do Until pdfjob.cCountOfPrintjobs = 1
- DoEvents
- Loop
- 'pdfjob.cPrinterStop = False
- 'Combine all PDFs into a single file and stop the printer
- With pdfjob
- .cCombineAll
- .cPrinterStop = False
- End With
- 'Wait until PDF creator is finished then release the objects
- Do Until pdfjob.cCountOfPrintjobs = 0
- DoEvents
- Loop
- pdfjob.cClose
- 'Reset the (original) default printer and release PDF Creator
- Set Application.Printer = Application.Printers(lPrinterCurrent)
- Set pdfjob = Nothing
- End Sub
Thank you.