Link to home
Start Free TrialLog in
Avatar of Member_2_4875898
Member_2_4875898Flag for United States of America

asked on

Open PDF file from access form

I need to be able to open a pdf file from access.  I found some code that works great for it but then they changed the way the filenames are on me.  The first 9 charecters of the filename are the same as the field in the form that is used to retrieve the PDF file.  It is a unique 9 digit part number so the first 9 charecters of the pdf file always match the part number.  Now they have added some information after the first 9 charecters.  I tried to add a wild card to the name to open the file since there  will be only on file with the first 9 charecters matching the part number but that did not work.  I have attached the code that I am using.  Any help would be appreciated.

Thank you.

Jeff
Private Sub cmd_display_drw_Click()
Dim fstFile As String
Dim varstrtec As String
Dim varstrhofniin As String
Dim flShowHow As Long
Dim s As String, sPath As String, I As Integer, iPosn As Integer
    s = CurrentDb.Name
    I = 0
    Do
        iPosn = InStr(Len(s) - I, s, "\")
        I = I + 1
    Loop Until iPosn > 0
    sPath = Left(s, iPosn)
On Error Resume Next
varstrtec = cmb_tec_select
varstrhofniin = cmb_niin_select
fstFile = sPath & "illustrations\" & varstrtec & "\" & varstrhofniin & ".pdf"
flShowHow = 3
fHandleFile fstFile, flShowHow
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just incidentally and nothing to do with your Q,

All of this ..
Dim s As String, sPath As String, I As Integer, iPosn As Integer
    s = CurrentDb.Name
    I = 0
    Do
        iPosn = InStr(Len(s) - I, s, "\")
        I = I + 1
    Loop Until iPosn > 0
    sPath = Left(s, iPosn)

can be replaced with..

spath =Currentproject.path & "\"
Avatar of Member_2_4875898

ASKER

Also I made the other change above and it does really clean things up a bit.  Could you clarify for me though why I have to use the dir() to open a file using a wild card.  I did try to place the "*.PDF" in my original code and it would not open.  What is the difference in how it handles files?

Thanks again for the help,

Semper Fi,

Jeff
I answered my own question on the difference.  It is actually running the DIR command to retreive a list of filenames so that you have the full string placed in the variable if it is the only file in the directory matching the criteria.  Thanks again for the help.