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

KenpachiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

peter57rCommented:
The important code is the fHandlefile code.

Looking at the code you have posted the only thing to do is use
     ...... & "*.pdf"

but it depends on how the file is processed in the other procedure.

If you are certain there is only one file that matches the name then you could do this to get the name..

fstFile = sPath & "illustrations\" & varstrtec & "\" & dir( sPath & "illustrations\" & varstrtec & "\" varstrhofniin & "*.pdf")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peter57rCommented:
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 & "\"
KenpachiAuthor Commented:
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
KenpachiAuthor Commented:
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.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.