Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to combine PDF's note quite correct.????

Status
Not open for further replies.

JMal

Programmer
Aug 19, 2004
61
IE
Hi there.

I have recieved help on this problem here before which worked out great:

Treat:
On using the advice form the above tread, I am now trying to slightly change the way the code calls the arguement.


I am using the following code to combine multiply PDF's for my access database.

stDocName = """C:\Program Files\PDF Doc's\Page 1.pdf"" ""C:\Program Files\PDF Doc's\Page 2.pdf"" ""C:\Program Files\PDF Doc's\Result.pdf"""



stAppName = "C:\pdf995\res\utilities\pdfcombine.exe"
Call Shell(stAppName & "" & stDocName, 1)

The results of this combine utility creates one PDF called Results containing all the PDF's in the stDocName, Page1 , page2 etc.


I have enhanced the above code as follows:

--------------------------------------------------------

Dim pag1 As String
Dim pag2 As String
Dim pag3 As String
Dim pag4 As String

pag1 = DLookup("[CombineExtension]", "Temp_Combine_Docs", "[SequenceNo] = 1")

pag2 = DLookup("[CombineExtension]", "Temp_Combine_Docs", "[SequenceNo] = 2")

pag3 = DLookup("[CombineExtension]", "Temp_Combine_Docs", "[SequenceNo] = 3")

rptFinal = "C:\Program Files\PDF Doc's\FinalPage.pdf"

stDocName = """" & [pag1] & """" & " " & """" & [pag2] & """" & " " & """" & [pag3] & """" & " " & """" & rptFinal & """"


Note: the [CombineExtension] has the location of the PDF stored in the field.
-------------------------------------------------------

The above code work great until one of the above documents (e.g. [pag2]) in not in the specified location and the final combines PDF document called rptFinal get corrupted.

Is there any way I can change the above stDocName part of my code to ignore if no document exists in the specified location.

The above code is a small version of the origional code which is set up to combine 20-30 PDF's at once.

Thanks in advance
 
JMal,

Here some sample code I use too test if a file (image in my case) is 1) a valid file name and 2) if it exits. Just modify this to test if the file is really there. Then instead of buillding your string "all at once" build it using a loop where you keep expanding the string (if you have a valid file).

Code:
' Default turn off image
   Forms!frmAssets.Controls!ImageAW.Visible = False
 nlCheck = IsNull(Graphic)     ' Test for a valid file name
If nlCheck = 0 Then
 Forms!frmAssets.Controls!ImageAW.Visible = True
  qualname = Graphic & ".tif"     
  On Error GoTo Errorg
 fileAttr = GetAttr(qualname)  ' Valid DOS file name?
  Me!ImageAW.Picture = qualname
End If
Exit Sub

Errorg:
    ' Invalid dos file name set to default
 Forms!frmAssets.Controls!ImageAW.Visible = False
    Exit Sub

Good Luck...

 
Hi HitechUser

Thanks for your reply. I am in the early days of VBA programming and not sure if I can manage your example.

I think I could manage to check if the PDf Doc is there or not, but not sure how to build the string using a loop to keep expanding the string if a file exists.

Can you give me a simple example for how to do this using my code above.

Sorry about my basic knowledge of VBA.

Thanks
 
JMal,

There are several examples of loops in the VBA help text. What I meant was to "expand" you strings value by appending to it. You can use a loop of just use an If statement.

Code not complete...
Code:
'This code assumes varValidFile is the variable you set.. example only
If varValidFile = 0 Then
  ' The "..." is ONLY to show you that you need to complete this line of code
  stDocName = stDocName & """" & ...         
 
End If

or this (NOT complete)
Code:
... test for valid file pag1
... if valid
stDocName = stDocName & """" & [pag1] ...
... end if
... test for valid file pag2
... if valid
stDocName = stDocName & """" & [pag2] ...
... end if
... test for valid file pag3
... if valid
stDocName = stDocName & """" & [pag3] ...
... end if

' You get the idea...
' I WOULD recommned loop.

Good Luck...

 
And what about something like this ?
stDocName = IIf(Dir(pag1) > "", """" & pag1 & """", "") _
& " " & IIf(Dir(pag2) > "", """" & pag2 & """", "") _
& " " & IIf(Dir(pag3) > "", """" & pag3 & """", "") _
& " """ & rptFinal & """"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top