1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Dos commands in Access 2007 vba

Discussion in 'Software Development' started by ianclegg, Apr 11, 2015.

Thread Status:
Not open for further replies.
Advertisement
  1. ianclegg

    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
     
  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    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? :)
     
  3. ianclegg

    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
     
  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    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
     
  5. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    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)
     
  6. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    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
     
  7. ianclegg

    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
     
  8. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,608
    First Name:
    Hans
    You're welcome, that's about the same idea that I mentioned as second answer.
    Happy coding :)
     
  9. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1146413

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice