Access Reports and PdfCreator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shimul
    New Member
    • Nov 2008
    • 28

    #1

    Access Reports and PdfCreator

    Hi All,
    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:

    Code:
    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
    Please advise.

    Thank you.
    Attached Files
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Before we look for the unknown, please tell us what you mean by "it doesn't work for me." In what way does it not work? And can you print individual reports to pdfs?

    Jim

    Comment

    • shimul
      New Member
      • Nov 2008
      • 28

      #3
      Hi Jim,

      I can print individual report.

      When I tried to combined, pdfcreator got freeze..

      Guess problem with the following code:

      Do Until pdfjob.cCountOf Printjobs = 1
      DoEvents
      Loop
      Thank you for your reply.

      Comment

      • dsatino
        Contributor
        • May 2010
        • 393

        #4
        What line is break point occurring?

        Comment

        Working...