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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a specific Word Document 7

Status
Not open for further replies.

smille777

Technical User
Jun 27, 2004
43
US
Hi Everybody.

Can anyone help with how to Open a specific Word Document with a button on a form?

Document path = C:\Documents and Settings\Scott Miller\My Documents\Maverick\Scott

Thnaks,

Scott
 
you can use:

Shell('full path to access' 'C:\Documents and Settings\Scott Miller\My Documents\Maverick\Scott.doc')

or open an automation instance and open the file through Word directly.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Robert,

Thanks for the post. Pardon me, but I have merely sccratched the surface of Access and am an infant in programming.

Can you explain the meaning of "shell" and where I would use: Shell('full path to access' 'C:\Documents and Settings\Scott Miller\My Documents\Maverick\Scott.doc')

Thanks,

Scott
 
Sure thing....

Shell is a built in function in Access that passes a string to a command line interface....the same as you opening a command window and typing in the string.

Word can be called from a command line by typing in the full path to word. For example, on my PC it is C:\Windows\Program Files\Microsoft Office\Office11\windword.exe If you place a path after that, it will open the specific file in question. So if I type the above and add C:\test.doc at the end, it will open Word with the test.doc file displayed.

Automation is the process where one Office application (Word, Excel, Access, Power Point) can open and control another. For example, I can use Access to open Outlook and send emails to someone in my address list, attaching a record from the access based diaplyed on a Word document. All fun and dandy if you have the experience. Until you get you feet wet with some VBA experience, I would recommnend staying away from automation. Its not really all that tough, but with some programming background and/or a mentor, you can quickly get in over your head.

To execute a Shell command from a button, you create the button on the form. If you use the wizard just pick anything as you will be deleting the code anyway. Open the proteries windw and select the button. Find the OnClick property. It should read "Event Procedure" If you click there a little ellipse (three dots) will appear to the right of the line. Click this and it will bring up the code window. Delete anything between the Private Sub Commandx_Click() and the End Sub. Place the code below in its place:

Code:
Dim RetVal As Variant     ' This is the variable to hold the result

RetVal = Shell('[i]path to word[/i]' '[i]path to file[/i]')

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
To be less dependent on the installed version of word, you may consider something like this:
Set Sh=CreateObject("WScript.Shell")
Sh.Run Chr(34) & "C:\Documents and Settings\Scott Miller\My Documents\Maverick\Scott.doc" & Chr(34)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks to Robert Johnson for your patience and in depth explnation. I look forward to learning more and more!!

Thanks to PHV!!!! AGAIN!!!!! I realized that I did not have the full document path at first, but was able to get your code to work!!!!!

Robert I tried your coding and may have typed it wrong, but I am receiving a "Compile Error: Syntax Error"

I have the following code:

Dim RetVal As Variant ' This is the variable to hold the result
RetVal = Shell('C:\Program Files\Microsoft Office\Office10\winword.exe' 'C:\Documents and Settings\Scott Miller\My Documents\Maverick\Scott\Scottfaxcover.doc')

Thanks again gentlemen!

Scott

 
This is just what I needed.

Can I use the Shell execute command as in VB where the actual path of the document does not have to be listed, but the program will obtain the file name from a text box and open the application based on the suffix (.pdf, in this case). I can do this in VB, but can't make the same work in Access.

here's the code in VB6:

Private Sub cmdOpenDoc_Click()
ShellExecute &O0, "Open", txtfields(11).Text, vbNullString, "", 1
End Sub

Any ideas??
 
I think PHV's suggestion is a wrapper for the ShellExecute API, which can be used in Access VBA too, see for instance Start an app with ShellExecute for a suggestion on implementation, or CajunCenturions explanation here thread705-892810.

Roy-Vidar
 
Hi and thanks.

I am using this code:

ShellExecute Me.hWnd, "Open", PDF.Text, vbNullString, "", 1

and I get the following message:

You can't reference a property or method for a control unless the control has the focus. PDF.Text is a text box where the name of a PDF file is stored for each record in the DB.

Any ideas?

The first article you referenced, I'm not sure where to put all the items included in that code. I'm learning VB by the "seat of my pants" unfortunately.

Kathy
 
He - he - mixing VB/Access VBA syntax;-)

.Text property needs the control to have focus, whilst the .Value property (or use the controlname without qualifying property) doesn't need focus (same as the VB .Text property, I guess).

Dev Ashis' code? In a standard module, call it as in the samples included in the code.

Roy-Vidar
 
How can I use the Shell command to open up a specific word file AND have it automatically go to a predefined bookmark within the Word document?

Thanks,
Steve
 
Hello all,

PHV's solution works great, but is there some way to make it more portable?

I have a folder in the same file as the database with several excel sheets in it. These will travel with the database, but what directory the database will end up under is unknown to me. Is there some way to make it start looking for a file from the folder the database file is in?

Also, sorry about digging up old threads.
 
In Access 2000+ versions.

[tt]Sh.Run Chr$(34) & currentproject.path & "\filename.xls" & Chr$(34)[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top