Open a word or pdf file via command button

I have a database that keeps track of resume applications. I would like to have a command button that would open a word or pdf document which the user adds the file name to a text box. E.g. - the user adds the name of a resume to a text box ' JoeSmithResume.doc' and the command button would search a specific directory and open that file.
dwainpatAsked:
Who is Participating?
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.

JezWaltersCommented:
Have you tried using Shell?
0
JezWaltersCommented:
I mean like this:

    Shell "WINWORD ""C:\Temp\YourDocument.doc"""
0
JezWaltersCommented:
If you'd like a bit more control, you can do this using ActiveX too (you'll need to add a Reference to the latest version of the Microsoft Word Object Library as well):
Public Sub OpenDoc(pstrDocument As String)
    Dim wrdApplication As Word.Application
 
    Set wrdApplication = CreateObject("Word.Application")
    wrdApplication.Visible = True
    wrdApplication.Documents.Open pstrDocument
End Sub

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

JezWaltersCommented:
Sorry, forgot about the windowstyle parameter for the Shell call!  Anyway, you could open a PDF file using the appropriate reader (I've got Acrobat Reader) like this:

    Shell "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32 ""C:\Temp\YourPDFFile.pdf""", vbNormalFocus
0
JezWaltersCommented:
Depending on your PDF reader software you can probably does this with ActiveX too (along the lines of how I showed you with Word) - but this is only worthwhile if Shell() is not good enough.

Let me know if you want the ActiveX code for opening PDF files - but I'll only be able to help with the Adobe Acrobat Reader interface.
0
sonchoyCommented:
Try this
Private Sub cmdOpenWord_Click()
 
Dim strWordDoc As String
    Dim openApp As Object
 
    'Get path to the word document
        
    strWordDoc = InputBox("Enter your file name and location as Directory:\filename.extension", "Enter File")
    
    ' search file
    
    If Dir(strWordDoc) = "" Then
        
        MsgBox "Document not found."
 
    Else
        'Create an instance of MS Word
        Set openApp = CreateObject(Class:="Word.Application")
        
        openApp.Visible = True
 
        'Open the Document
        openApp.Documents.Open filename:=strWordDoc
        
    End If
End Sub

Open in new window

0
dwainpatAuthor Commented:
Thank you, you're on the right track. But how can I get the command button to automatically extract the file name that was entered in the text box (in other words, skip the input box)?
0
sonchoyCommented:
strWordDoc = "c:\file.doc"
0
sonchoyCommented:
if you don't wanna use inputbox, Just write your directory and file name to assign in
strWorkDoc
0
sonchoyCommented:
Did it work?
0
jefftwilleyCommented:
How about something simple

FollowHyperlink "C:\MyFolder\" & me.MyTextbox

Works for most applications as long as there is a system file association.

J

0

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
dwainpatAuthor Commented:
Works exactly the way I want. Sometimes simple is all you need. Thanks.
0
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.