Solved: Dos commands in Access 2007 vba

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ianclegg

Thread Starter
Joined
Jan 25, 2010
Messages
3
Hoping that someone can help!


I am developing a search system for our family history group and have a problem, I fixed it last week but since then have screwed up the code somehow and get an error message of type mismatch every time I run it now.


I need to merge a number of PDF files together to make a complete extraction print. Last week I was successfully using the Pdf Toolkit Server version (PDFTK). My parameters were I hope


dim PDFTKString as string


pdftkstring = "PDFTK c:\input1.pdf c:\input2.pdf cat output c:\output1.pdf


docmd.runcommnd (pdftkstring)


My code got to the end of processing and created all the output files to merge, loaded a dos box and processed the pdftk commands, created the output file and completed ok.


Now on running the code I get a type mismatch error at the docmd line.


The pdf toolkit can be found by searching the internet for pdftk.


Any ideas would be gratefully received.


Thanks in anticipation


Ian Clegg
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
Hi Ian,
welcome to the forum.
Can you post the vba code for this dos command? Will make it easier to see instead of guessing at all the possibilities wher it might go wrong? :)
 

ianclegg

Thread Starter
Joined
Jan 25, 2010
Messages
3
Hi, Thanks for the reply. The code was posted in the original question. I have repeated it again below. Since the original post, I have tried a number of other methods using shell etc, I have still failed.


I am trying to merge a number of pdf files together using PDFTK (Pdf toolkit Server). I have built up the string of files to merge in a string and have submitted that to the code. Any help at all would be very helpful.


dim PDFTKString as string

pdftkstring = "PDFTK c:\input1.pdf c:\input2.pdf cat output c:\output1.pdf

docmd.runcommand ("pdftkstring")




Regards
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
Sorry, I did not read that as the code, my excuses.
You mention that if you do this manually it works but not if you use the code, right?

Have you tried adding the path to PDFTK.exe?
You will have to use "" here too because spaces don't go well within variables
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
Well, you got your syntax all wrong:

Code:
Sub pdfmerge()
Dim PDFTKString As String
PDFTKString = "PDFTK " & Chr(34) & "G:\_ONTWIKKEL\documenting vba projects\Prf_Lee_Twonsend-Hartford_University.pdf" & Chr(34) & Space(1) & Chr(34) & "G:\_ONTWIKKEL\documenting vba projects\Prof_Lee_Townsend-uhaweb_Hartford.pdf" & Chr(34) & " cat output " & Chr(34) & "G:\Temp\merged.pdf" & Chr(34)
Debug.Print PDFTKString
Shell PDFTKString
End Sub
The above example works here, you just replace the path and filemas, leave the quotes and the Chr(34)
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
If you do it as this you can add functionality:

Code:
Sub mergePdffiles()
Dim file1 As String
Dim file2 As String
Dim oFile As String

file1 = "G:\_ONTWIKKEL\documenting vba projects\Prf_Lee_Twonsend-Hartford_University.pdf"
file2 = "G:\_ONTWIKKEL\documenting vba projects\Prof_Lee_Townsend-uhaweb_Hartford.pdf"
oFile = "G:\Temp\merged.pdf"
Call pdfmerge(file1, file2, oFile)
End Sub

Function pdfmerge(file1 As String, file2 As String, oFile As String)
Dim PDFTKString As String
PDFTKString = "PDFTK " & Chr(34) & file1 & Chr(34) & Space(1) & Chr(34) & file2 & Chr(34) & " cat output " & Chr(34) & oFile & Chr(34)
Debug.Print PDFTKString
Shell PDFTKString

End Function
Testd it and it works
 

ianclegg

Thread Starter
Joined
Jan 25, 2010
Messages
3
Thanks again for all your help and suggestions. I have finally solved my problem. My method was to set up a variable for each report I need to Merge.


' Populate Report Variables


Report1 = Environ("userprofile") & "\documents\BHFH_Report_Header1.pdf "
Report2 = Environ("userprofile") & "\documents\BHFH_Report_Header2.pdf "
Report3 = Environ("userprofile") & "\documents\BHFH_Report_Header3.pdf "


Then use the shell command to merge the reports into the output file.

Call Shell("pdftk " + Report1 + " " + Report2 + " " + "cat output " + Report3)


Once again Thank you. Problem Solved


Regards
 

Keebellah

Hans
Trusted Advisor
Joined
Mar 27, 2008
Messages
6,639
You're welcome, that's about the same idea that I mentioned as second answer.
Happy coding :)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top