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

OPENING MICROSOFT WORD FILE FROM ACCESS

Status
Not open for further replies.

Kevsim

Instructor
Apr 18, 2000
385
0
0
AU
While working in Access, there are times I require to open a Word or Excel file, say from a command button. I would appreciate some advise on how to do this.
kevsim

 
In the database window, choose " macro">New and select the RunApp command in the dropdown box on the line you want.
Type the path in the box underneath
 
PepeLeMokko, Thanks for the info. I tried what you said, and only typing the path C:\My Documents gave the following error message "The path is invalid or a component of the application is missing",could you please advise what I am doing wrong.
kevsim
 
You should enter the path to the application itself i.e.
D:\Program Files\Microsoft Office\Office\word.exe ( if this is the path to the application)
But why do you want to open word?
To extract values, mail merge?
 
PepeLeMokko, Thanks for the info. I tried what you said, I received the same error message. I shortened the path to only Program Files, still the same message. Could you please advise what I am doing wrong.
kevsim
 
Hi

Word application is 'winword.exe' not 'word.exe' whatever directory it is in!

Tony
 
You could have a field in one of your tables that stores the WORD FILE NAME of the document you want to open that relates to your current info on the form. (The name MUST match the Word FILE name) Create your command button and place the following code on the OnClick event:


Private Sub Command78_Click()
DoCmd.Hourglass True
GetInstrPro Instpro:=Me![FormName].[ControlName]
DoCmd.Hourglass False
End Sub

Sub GetInstrPro(Instpro)
Dim appWord As Word.Application
Dim wd As String
On Error Resume Next
wd = "c:" & "\" & Instpro & ""
AppActivate "Microsoft Word"
If Err Then
Shell "c:\Program Files\Microsoft Office\Office\Winword /Automation", vbMaximizedFocus
AppActivate "Microsoft Word"
End If
On Error GoTo 0
Set appWord = GetObject(, "Word.Application")
With appWord
.Visible = True
.Documents.Open Filename:=wd
.ActiveDocument.ShowSpellingErrors = False
End With
Set appWord = Nothing
End Sub

Neil
 
Winword should be on the path, so shell ("Winword") should work, and it does, and you don't need the pathname at all.

If you're going to be distributing your macro, it's better again because you don't need to worry where word is installed to

HTH
Paul
 
Hello Kevsim,
If you want to keep it simple. . .

In Form design view use the "Command Button" control to create a new command button (make sure the "Wizard" button is on). After creating the cmdButton the Wizard should appear. On the left hand side choose "Application" and on the right side will be a list of available applications.

Hope this helps,
Michael
 
None of the above suggestions, except mine, tells you how to open a file in Word or Excel. They just open the application. You asked how to open a FILE.

Forgot to tell you. Place all your documents in the same folder. That way, in the code, the path name will always be the same.

Neil
 
Code:
shell("winword drive:\pathname\filename)
will open the specified document

Paul
 
If you hyperlink the file to a button, or label it will open the file also. In the properties of the button or label, click on format, click on hyperlink address, click the three dots, browse to the file, click okay.
 
I thank you all for the assistance in solving my problem. CathieB, the hyperlink was one thing I missed, thank you, can you do the same to only go to a particular folders contents?
kevsim




 
To all of the respondants, I have found this information to be almost just what I needed!! The missing piece is the creation of the WORD document from within ACCESS, utilizing the specific record (JOBnumber) as part of the WORD document filename. (Therefore each JOB would have it's own document and I would not have to create it prior to attempting to access it the first time.) This would require specifying the path so all documents would be in the same location. ANY AND ALL HELP, WOULD BE APPRECIATED!!!
 
Code:
Path = "Where\you\want\to\put\your\files\"
FileName = Driveletter & ":\" & Path & "ART_" & JOBnumber & ".doc"
shell("winword " & FileName)

Should be all you need


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top