Opening a Word Document via a button control on a form

Sym

Registered User.
Local time
Today, 02:59
Joined
Feb 21, 2015
Messages
40
I would like to open a Word document using a button control on a form to a file path listed in a field on the form. I use the following code when I want to open a single specific document...

Dim wdApp As Word.Application, wdDoc As Word.Document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open(File path here)
wdApp.Visible = True

...but in this case the file path I want to use will be designated by a field on the form. I know I could just use a hyperlink but I don't like the way it looks on the form. I would rather hide that field and have code pull that path when I hit the button.

So how would I change my code to make it so the value in the file path field on the form goes in where it says "File path here" in my code above?

thanks
 
Code:
Set wdDoc = wdApp.Documents.Open([COLOR=red]Me.YourControlName[/COLOR])
 
The hyperlink path does not need to be displayed on the form, just display the name. Either a function to extract and display OR an extra field that stores the name.

That way your code is simplified to
Code:
Application.FollowHyperlink Me.PathToWordDocField
 

Users who are viewing this thread

Back
Top Bottom