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

How do i open an existing word file??

Status
Not open for further replies.

smit

Programmer
Oct 1, 2001
11
GB
Ok i can create buttons to run word, however is there any way at all to make it open an existing Word file??

thanx alot in advance, i'm using access 2000 if that helps :)

Smit
 
The following code will open an existing word document.


Dim appWord As New Word.Application
Dim docWord As Word.Document
Dim strPath As String
'set the path to the document to open
strPath = "C:\Test\Test.doc"
'make the word application visible
appWord.Visible = True
'open the document
Set docWord = appWord.Documents.Open(strPath)
'make word the active window
appWord.Activate


Hope this is what you are looking for.
 
Another method would be to use a Call Shell method if you know the exact path of the application and the location of the file.

Example:

Call Shell("C:\program files\Microsoft Office\Office\winword.exe C:\classificationchanges.doc", 1)

 
Hi,

A more generic approach (ie. if you may need to access different doc types):

Private Sub cmdDocLink_Click()
Dim strMyFile As String
Dim ctl As CommandButton
Const cstUNCPath As String = "\\myserver\mypath"
Const cstPathChars As Integer = 39

strMyFile = cstUNCPath & Me.DocumentUNC.Value
If Dir(strMyFile) <> &quot;&quot; Then
If Len(strMyFile) > cstPathChars Then
Set ctl = Me!cmdDocLink
With ctl
.HyperlinkAddress = strMyFile
.Hyperlink.Follow
End With
End If
Else: MsgBox &quot;File Path is Incorrect! Please check and re-enter.&quot;
End If
DoCmd.ShowToolbar &quot;Web&quot;, acToolbarNo

End Sub

You don't need to use the const containing the server name etc and you can change it to whatever u like.

This code is for a command button which takes the value of a text box on my form and concatenates it with the constant for the server name & path to producce a full UNC path. It can be a web address also.

The last line hides the web toolbar (cos it appears automatically when you click a hyperlink).

HTH,
Burns
 
thanx a lot for all the help i'll have a go and get back to u :)
 
agghhhrrr :-( i've just got into access and attempted all these things and realised that my VB skills are non existant!!!

Bonusmarch, ur technique intruiged me, how/where do i put that call shell function into my database so that a Word doc can be opened ????

thanx again for all ur help so far ppl :)

Smit
 
The most common place would be to put it in a buttons 'click' event.
 
i've just tried that and it brings up the error message:

---------------------------------------------------
microsoft access cannot find the macro 'Call Shell(&quot;C:\program files\Microsoft Office\Office\winword.'

The macro (or its macro group) doesn't exist, or the macro is new and hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macro's macro group was last saved under.
---------------------------------------------------
this is a bit wierd as i have not been any where near any macros?!?

please help again :)

Smit
 
I think I know what you did. You do not want to enter the code in the line of the click event. When you bring up the properties of the button go to the event tab. click on the 'onclick' event and then select the ... box to the right. This will open up the code editor window and you should see some code that says:

Private Sub myButton_Click()

End Sub

you want to enter the code here so that it should look like the following:


Private Sub myButton_Click()
Call Shell(&quot;C:\program files\Microsoft Office\Office\winword.exe C:\classificationchanges.doc&quot;, 1)
End Sub


 
Good GOD people. He asked for the time, not how to build a watch! :)

Create the command button on a form, choose application, run applictaion (NOT &quot;Run MS Word&quot;)

For the command line type

winword c:\mytextfile.doc

that's it! I've had a problem with files or directory trees with spaces in them though.
 
Good point ErikZ. I guess I never use the wizard that often that it did not dawn on me. That is definitely the easiest way to do though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top