Opening Word document from access 2000 command button

Slow Learner

Registered User.
Local time
Today, 09:03
Joined
Oct 7, 2004
Messages
17
How do can I open a word document from a command button. It does not want to see my file location and keeps telling me there is no document.
Just looking for a simple on click procedure that will open word and then open a file.
 
Here is the code I used

Private Sub cmdWord1_Click()

Dim WordDoc As String
Dim oApp As Object

'Path to the word document WordDoc = "c:\test.doc"

If Dir(WordDoc) = "" Then
MsgBox "Not here"

Else
'Create an instance of MS Word
Set oApp = CreateObject(Class:="Word.Application")
oApp.Visible = True

'Open the Document
oApp.Documents.Open filename:="c:\test.doc"
End If

End Sub

:confused: This opens word but is failing to find the file which is as shown, unless c has to be C: (I will try this but...).

It gives me a Run-time error '5174';
This file could not be found.
Try one or more of the following:
*Check the spelling of the name of the document.
*Try a different file name.
(c:\test.doc)


Any other suggestions, tips or words of wisdon?? Thanks
 
Use the Shell() function or the Application.FollowHyperlink method. Search the Access help files or this forum for more info and examples.

Also, you are not using the Dir() function correctly to test if the file exist.

If Dir("C:\Test\MyFile.doc") = "" Then
'file does not exist
Else
'file does exist
End If
 
Last edited:
Private Sub cmdViewDocument_Click()
On Error GoTo Err_cmdViewDocument_Click
Dim objword As Object
Set objword = CreateObject("Word.Application")

objword.Visible = True
objword.Documents.Open (Me.QuoteDocumentPath)

Exit_cmdViewDocument_Click:
Exit Sub

Err_cmdViewDocument_Click:
MsgBox Err.Description, , "Service Operations"
Resume Exit_cmdViewDocument_Click

End Sub
 

Users who are viewing this thread

Back
Top Bottom