Access: Desire simple, clear code example for merging files

About the programming interface for the virtual PDF printer driver.

Moderator: jr

jjaeger
Posts: 5
Joined: Tue Mar 24, 2015 2:22 pm

Access: Desire simple, clear code example for merging files

Post by jjaeger »

I desire a simple, clear, concise code vba code example that I can plug into an Access database for merging multiple .pdf files.

So if I have the following:

c:\test\report1.pdf
c:\test\report2.pdf
c:\test\report3.pdf
c:\test\report4.pdf
c:\test\report5.pdf
c:\test\report6.pdf

And I desire these to be merged into:

c:\test\FinalReport.pdf

How do I accomplish this in an Access VBA Code Module? I banged my head on this website and the internet in general attempting to accomplish with Bullzip to no avail.

I accomplished this using PDF Redirect but I had to research and purchase and educate myself on that code because Bullzip and the Bullzip forum does not provide clear and concise code example. This is how I accomplished it using the above software and I consider this to be clear and concise. PLEASE SUPPLY SOMETHING SIMILAR ON YOUR SITE.


Run this from a debug window:

subMerge 6, "c:\test\"

Public Sub subMerge(reportcount as integer, strPath as string)
'note: assumes 'PDF redirect Pro Remote Control' is installed as a library in Tools/References
'note: you might use docmd.outputto... code to send reports to desired locations as .pdf files prior to running this code

Dim oPDF As New PDF_reDirect_v25002.Batch_RC_AXD
Dim Files_to_Merge(200) As String
Dim TempBool As Boolean

For j = 1 To reportcount
If (LenB(strPath & "tempPdf" & j & ".pdf") > 0) Then

Files_to_Merge(j) = strPath & "tempPdf" & j & ".pdf"

End If
Next j

TempBool = oPDF.Utility_Merge_PDF_Files(strPath & strFileName, Files_to_Merge)

If Not TempBool Then
' NOTES ON ERROR CODES for oPDF.ErrorLastDLL
' 401 - One of the Input File could not be opened
' 410 - One of the Input File could not be decrypted
MsgBox "An Error Occured: " & oPDF.LastErrorDescription & vbCrLf & _
"Error Number =" & Str$(oPDF.LastErrorNumber) & vbCrLf & _
"DLL Error Number =" & Str$(oPDF.ErrorLastDLL), _
vbExclamation
End If

Set oPDF = Nothing

End Sub
jr
Site Admin
Posts: 500
Joined: Sun Mar 26, 2006 12:28 pm

Re: Access: Desire simple, clear code example for merging fi

Post by jr »

Hi,

I have created a small VB Script that shows you how to do that. You should be able to convert that to VBA without any problems.

Sub TestMerge2(currentdir)
Dim objUtil
Dim output, input1, input2, input3

Set objUtil = CreateObject("Bullzip.PdfUtil")

output = currentdir & "\out\Test Merge2.pdf"

Rem -- Define input files to get merged
input1 = currentdir & "\in\1.pdf"
input2 = currentdir & "\in\2.pdf"
input3 = currentdir & "\in\3.pdf"

Rem -- Remove output files if they already exist
if fso.FileExists(output) then fso.DeleteFile output

Rem -- Do the merge
objUtil.Merge2 input1 & "|" & input2 & "|" & input3, output, objUtil.DefaultPrinterName, 30000

Rem -- Check if the merged document exist
if not fso.FileExists(output) then
wscript.echo "Merge2 test failed"
wscript.quit 1
end if
End Sub

I hope this helps :-)

Regards,
Jacob
jjaeger
Posts: 5
Joined: Tue Mar 24, 2015 2:22 pm

Re: Access: Desire simple, clear code example for merging fi

Post by jjaeger »

Thanks for the quick reply.
jjaeger
Posts: 5
Joined: Tue Mar 24, 2015 2:22 pm

Re: Access: Desire simple, clear code example for merging fi

Post by jjaeger »

This example does not translate simply into Access. I'm trying to fix now. Thank you for the code slice so far.

What libraries are required? Just the 'Bullzip' library?
jjaeger
Posts: 5
Joined: Tue Mar 24, 2015 2:22 pm

Re: Access: Desire simple, clear code example for merging fi

Post by jjaeger »

This line of code does not work. Maybe I need a different library installed?

Please note I'm using this in an Access 64 bit installation.

'objUtil.Merge2 input1 & "|" & input2 & "|" & input3, output, objUtil.DefaultPrinterName, 30000'
Yields error: '438: Object doesn't support this property or method
jjaeger
Posts: 5
Joined: Tue Mar 24, 2015 2:22 pm

Re: Access: Desire simple, clear code example for merging fi

Post by jjaeger »

I've installed all of the Bullzip libraries available in my Access project. Still get error 438.
Post Reply