Results 1 to 10 of 10
  1. #1
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110

    Convert multiple form to pdf

    Hi Guys,



    Anyone know how to convert multiple form into 1 pdf file?

    For Form1 export to PDF :
    DoCmd.OutputTo acOutputForm, "Form1", acFormatPDF, "C:\Fortest\records" & [Forms]![Form1]![txtname] & " Record.pdf", True

    What if i have form 1 and form 2 need to convert it into 1 pdf?

    Any code? Any advise?

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,421
    Maybe
    Code:
    DoCmd.OutputTo acOutputForm, "Form1" & "Form2", acFormatPDF, "C:\Fortest\records" & [Forms]![Form1]![txtname] & " Record.pdf", True

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,960
    Tested. Doesn't work. Code looks for a form named "Form1Form2" which doesn't exist.

    Will have output each form individually. Then use automation code to manipulate the PDF files and combine.

    Or build report/subreport and try exporting that object.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by davegri View Post
    Maybe
    Code:
    DoCmd.OutputTo acOutputForm, "Form1" & "Form2", acFormatPDF, "C:\Fortest\records" & [Forms]![Form1]![txtname] & " Record.pdf", True
    Tested. Not working

  5. #5
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    Tested. Doesn't work. Code looks for a form named "Form1Form2" which doesn't exist.

    Will have output each form individually. Then use automation code to manipulate the PDF files and combine.

    Or build report/subreport and try exporting that object.
    Not sure how to do it. Can advise?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,960
    Do what - build a report? Or combine PDFs?

    Review https://www.accessforums.net/showthread.php?t=25574
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    Do what - build a report? Or combine PDFs?

    Review https://www.accessforums.net/showthread.php?t=25574
    Merge the PDF.

    I found this code in the thread.

    Code:
    Sub BatchMergePDF()Dim fso As Object, SourceFolder As Object, SFolder As Object, SSFolder As Object, SSSFolder As Object, PDFile As Object
    'Relies on the Adobe Acrobat 6.0 Type Library
    Dim objCAcroPDDocDestination As Acrobat.AcroPDDoc
    Dim objCAcroPDDocSource As Acrobat.AcroPDDoc
    Dim i As Integer, booMerge As Boolean
    'Initialize the objects
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = fso.GetFolder("R:\Projects\LabReportsOLD\")
    For Each SFolder In SourceFolder.subfolders
        For Each SSFolder In SFolder.subfolders
            If SSFolder.Name <> "Soils & Aggregate" Then
                i = 1
                For Each PDFile In SSFolder.Files
                    If i = 1 Then
                        objCAcroPDDocDestination.Open SSFolder.Path & "\" & PDFile.Name
                    End If
                    If i > 1 Then
                        objCAcroPDDocSource.Open SSFolder.Path & "\" & PDFile.Name
                        objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
                        objCAcroPDDocSource.Close
                    End If
                    i = i + 1
                Next
                objCAcroPDDocDestination.Save 1, SFolder.Path & "\" & SSFolder.Name & ".pdf"
                objCAcroPDDocDestination.Close
            Else
                For Each SSSFolder In SSFolder.subfolders
                    i = 1
                    For Each PDFile In SSSFolder.Files
                        If i = 1 Then
                            objCAcroPDDocDestination.Open SSSFolder.Path & "\" & PDFile.Name
                        End If
                        If i > 1 Then
                            objCAcroPDDocSource.Open SSSFolder.Path & "\" & PDFile.Name
                            objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
                            objCAcroPDDocSource.Close
                        End If
                        i = i + 1
                    Next
                    objCAcroPDDocDestination.Save 1, SFolder.Path & "\Soils & Aggregate " & SSSFolder.Name & ".pdf"
                    objCAcroPDDocDestination.Close
                Next
            End If
        Next
    Next
    Debug.Print SFolder.Name
    Set PDFile = Nothing
    Set SFolder = Nothing
    Set SSFolder = Nothing
    Set SSSFolder = Nothing
    Set SourceFolder = Nothing
    Set fso = Nothing
    Set objCAcroPDDocSource = Nothing
    Set objCAcroPDDocDestination = Nothing End Sub
    DoCmd.OutputTo acOutputForm, "Form1", acFormatPDF, "C:\Fortest\records" & [Forms]![Form1]![txtname] & " Record.pdf", True (One PDF)
    DoCmd.OutputTo acOutputForm, "Form2", acFormatPDF, "C:\Fortest\records" & [Forms]![Form2]![txtname] & " Record.pdf", True (2nd PDF)

    I've 2 saved PDF, in the code that you've provided. The code should be replace with C:\Fortest\records to merge the PDF.
    I cannot figure out which phase i should replace the code. Can you please help me?

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,960
    Your code is constructing a filename as recordsSomethingRecord.pdf.

    If records is a folder then it needs to be followed by a \.

    DoCmd.OutputTo acOutputForm, "Form1", acFormatPDF, "C:\Fortest\records\" & [Forms]![Form1]![txtname] & " Record.pdf", True (One PDF)
    DoCmd.OutputTo acOutputForm, "Form2", acFormatPDF, "C:\Fortest\records
    \" & [Forms]![Form2]![txtname] & " Record.pdf", True (2nd PDF)

    Then I suppose the SourceFolder variable would be set to: "C:\Fortest\records"


    Set SourceFolder = fso.GetFolder("C:\Fortest\records")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    onlylonely is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2017
    Posts
    110
    Quote Originally Posted by June7 View Post
    Your code is constructing a filename as recordsSomethingRecord.pdf.

    If records is a folder then it needs to be followed by a \.

    DoCmd.OutputTo acOutputForm, "Form1", acFormatPDF, "C:\Fortest\records\" & [Forms]![Form1]![txtname] & " Record.pdf", True (One PDF)
    DoCmd.OutputTo acOutputForm, "Form2", acFormatPDF, "C:\Fortest\records
    \" & [Forms]![Form2]![txtname] & " Record.pdf", True (2nd PDF)

    Then I suppose the SourceFolder variable would be set to: "C:\Fortest\records"


    Set SourceFolder = fso.GetFolder("C:\Fortest\records")
    Hi June,

    Thanks for your reply. But still not able to make it.
    When i run the code. It comes out "Run time Error 429, ActiveX component can't create object"


    Code:
    Sub BatchMergePDF()
    Dim fso As Object, SourceFolder As Object, SFolder As Object, SSFolder As Object, SSSFolder As Object, PDFile As Object
    'Relies on the Adobe Acrobat 6.0 Type Library
    Dim objCAcroPDDocDestination As Acrobat.AcroPDDoc
    Dim objCAcroPDDocSource As Acrobat.AcroPDDoc
    Dim i As Integer, booMerge As Boolean
    'Initialize the objects
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = fso.GetFolder("C:\Users\records\1\")
    For Each SFolder In SourceFolder.subfolders
        For Each SSFolder In SFolder.subfolders
            If SSFolder.Name <> "Soils & Aggregate" Then
                i = 1
                For Each PDFile In SSFolder.Files
                    If i = 1 Then
                        objCAcroPDDocDestination.Open SSFolder.Path & "\" & PDFile.Name
                    End If
                    If i > 1 Then
                        objCAcroPDDocSource.Open SSFolder.Path & "\" & PDFile.Name
                        objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
                        objCAcroPDDocSource.Close
                    End If
                    i = i + 1
                Next
                objCAcroPDDocDestination.Save 1, SFolder.Path & "\" & SSFolder.Name & ".pdf"
                objCAcroPDDocDestination.Close
            Else
                For Each SSSFolder In SSFolder.subfolders
                    i = 1
                    For Each PDFile In SSSFolder.Files
                        If i = 1 Then
                            objCAcroPDDocDestination.Open SSSFolder.Path & "\" & PDFile.Name
                        End If
                        If i > 1 Then
                            objCAcroPDDocSource.Open SSSFolder.Path & "\" & PDFile.Name
                            objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
                            objCAcroPDDocSource.Close
                        End If
                        i = i + 1
                    Next
                    objCAcroPDDocDestination.Save 1, SFolder.Path & "\Soils & Aggregate " & SSSFolder.Name & ".pdf"
                    objCAcroPDDocDestination.Close
                Next
            End If
        Next
    Next
    Debug.Print SFolder.Name
    Set PDFile = Nothing
    Set SFolder = Nothing
    Set SSFolder = Nothing
    Set SSSFolder = Nothing
    Set SourceFolder = Nothing
    Set fso = Nothing
    Set objCAcroPDDocSource = Nothing
    Set objCAcroPDDocDestination = Nothing
    End Sub

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,960
    The code example I referenced is designed to automatically merge a large number of files from multiple folders and subfolders. I doubt you need anything this complex and some of it is irrelevant to your situation - such as the line saving file with the name of "Soils & Aggregate " & SSSFolder.Name & ".pdf"

    Adapt code for your requirements. At its simplest:

    Code:
    Sub MergePDF()
    'Relies on the Adobe Acrobat x.0 Type Library
    Dim objCAcroPDDocDestination As Acrobat.AcroPDDoc
    Dim objCAcroPDDocSource As Acrobat.AcroPDDoc
    'Initialize the objects
    Set objCAcroPDDocDestination = CreateObject("AcroExch.PDDoc")
    Set objCAcroPDDocSource = CreateObject("AcroExch.PDDoc")
    
    objCAcroPDDocDestination.Open "C:\Fortest\records\" & [Forms]![Form1]![txtname] & " Record.pdf", 
    objCAcroPDDocSource.Open "C:\Fortest\records\" & [Forms]![Form2]![txtname] & " Record.pdf", 
    objCAcroPDDocDestination.InsertPages objCAcroPDDocDestination.GetNumPages - 1, objCAcroPDDocSource, 0, objCAcroPDDocSource.GetNumPages, 0
    objCAcroPDDocDestination.Save 1, "C:\Fortest\records\NewName.pdf"
    End Sub
    However, the only place I've ever run this code is at work. I seem to remember requires having Adobe Acrobat Standard at least installed, not just Adobe Reader. A quick search today supports that recollection. I am not able to run at home.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Convert memo field to multiple text fields
    By hertfordkc in forum Access
    Replies: 3
    Last Post: 11-14-2014, 06:59 AM
  2. Replies: 0
    Last Post: 08-18-2014, 12:27 PM
  3. Replies: 6
    Last Post: 05-09-2013, 11:00 PM
  4. Convert multiple reports to one PDF
    By utstrat03 in forum Reports
    Replies: 6
    Last Post: 02-27-2013, 04:35 PM
  5. Convert multiple rows to columns?
    By NelsonKauley in forum Programming
    Replies: 2
    Last Post: 04-04-2012, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums