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
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) <> "" Then
If Len(strMyFile) > cstPathChars Then
Set ctl = Me!cmdDocLink
With ctl
.HyperlinkAddress = strMyFile
.Hyperlink.Follow
End With
End If
Else: MsgBox "File Path is Incorrect! Please check and re-enter."
End If
DoCmd.ShowToolbar "Web", 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).
i've just tried that and it brings up the error message:
---------------------------------------------------
microsoft access cannot find the macro 'Call Shell("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?!?
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("C:\program files\Microsoft Office\Office\winword.exe C:\classificationchanges.doc", 1)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.