Combining multiple reports into a PDF export

alekkz

Registered User.
Local time
Today, 09:07
Joined
Oct 14, 2016
Messages
28
Hi,

I have this section of code handling the export of a single report into a pdf file into a specific pre-determined location. I would like to make it so that the export combines 2 reports as it is exporting into the pdf. I dont know where to begin. also I apologize for the code in advance I made this several years ago and its been in my archive folder since and I recently pulled it out and am starting to work on this again.


Code:
Private Sub Command21_Click()
 
  Dim fileName As String, fldrPath As String, filePath As String
  Dim answer As Integer
  Dim fileName2 As String

  DoCmd.OpenForm "Specific_Information_frm"
  'filename for PDF file*
  fileName = "C-Scan Report"
  fileName2 = Forms![Specific_Information_frm]![WBS Number]
  'folder path where pdf file will be saved *
  fldrPath = "C:\Users\#######\OneDrive - #####\Desktop"
 
  filePath = fldrPath & "\" & fileName2 & " " & fileName & ".pdf"
 
  'check if file already exists
  If FileExist(filePath) Then
    answer = MsgBox(prompt:="PDF file already exists: " & vbNewLine & filePath & vbNewLine & vbNewLine & _
      "Would you like to replace existing file?", buttons:=vbYesNo, Title:="Existing PDF File")
    If answer = vbNo Then Exit Sub
  End If
 
  On Error GoTo invalidFolderPath
  DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath
  DoCmd.Close acForm, "Specific_Information_frm"
  DoCmd.Close acReport, "C-Scan_rpt"
  MsgBox prompt:="PDF File exported to: " & vbNewLine & filePath, buttons:=vbInformation, Title:="Report Exported as PDF"
  Exit Sub
 
invalidFolderPath:
  MsgBox prompt:="Error: Invalid folder path. Please update code.", buttons:=vbCritical
 
End Sub
 
If you have Adobe Acrobat Pro or Adobe Acrobat Standard, you can use VBA to insert/delete pages to/from pdf files.
You'll have two options:
Run a VBA code
OR
Create a JavaScript code in VBA and run the script from VBA.
JavaScript has more power and options because Adobe Acrobat uses JavaScript as its programming language.

If you need the exact code, simply ask.
 

Users who are viewing this thread

Back
Top Bottom