?
Solved

Open a word or pdf file via command button

Posted on 2008-02-01
12
Medium Priority
?
1,497 Views
Last Modified: 2013-11-28
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.
0
Comment
Question by:dwainpat
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 17

Expert Comment

by:JezWalters
ID: 20798883
Have you tried using Shell?
0
 
LVL 17

Expert Comment

by:JezWalters
ID: 20798917
I mean like this:

    Shell "WINWORD ""C:\Temp\YourDocument.doc"""
0
 
LVL 17

Expert Comment

by:JezWalters
ID: 20798964
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 17

Expert Comment

by:JezWalters
ID: 20799018
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
 
LVL 17

Expert Comment

by:JezWalters
ID: 20799068
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
 
LVL 2

Expert Comment

by:sonchoy
ID: 20799502
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
 

Author Comment

by:dwainpat
ID: 20799648
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
 
LVL 2

Expert Comment

by:sonchoy
ID: 20800091
strWordDoc = "c:\file.doc"
0
 
LVL 2

Expert Comment

by:sonchoy
ID: 20800103
if you don't wanna use inputbox, Just write your directory and file name to assign in
strWorkDoc
0
 
LVL 2

Expert Comment

by:sonchoy
ID: 20800683
Did it work?
0
 
LVL 34

Accepted Solution

by:
jefftwilley earned 500 total points
ID: 20802844
How about something simple

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

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

J

0
 

Author Closing Comment

by:dwainpat
ID: 31427225
Works exactly the way I want. Sometimes simple is all you need. Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question