How can I make a button to open a particular MS Word Doc?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I make a button to open a particular MS Word Doc? I want to design a
button on my Switchboard to open a particular document.

Thanks,

John
 
jmuirman said:
How can I make a button to open a particular MS Word Doc? I want to
design a button on my Switchboard to open a particular document.

Application.FollowHyperlink "Path to file"
 
jmuirman said:
Sorry I'm a novice --what do I do with this - do i paste it somewhere?

Yes, you paste it into the Click event definition of your button.

Form in design view
Add button
Go to On Click event property
Enter "[Event Procedure]"
Click builder [...] button
In VBA code window enter...

Application.FollowHyperlink "Path to file"

....between the lines the define the start and end of the button's click event
sub-routine. Obviously you replace "Path to file" with the actual path to the
DOC you want to open.
 
I get an error : "Doc can't be found"

Here's my code - do i have it in the right place?

Thanks,

John

stDocName = "Newsletter - Trifold"
DoCmd.OpenReport stDocName, acPreview

Exit_Command94_Click:
Exit Sub

Err_Command94_Click:
MsgBox Err.Description
Resume Exit_Command94_Click

End Sub
Private Sub Command95_Click()
On Error GoTo Err_Command95_Click

Dim stDocName As String

stDocName = "Contacts by CLIENT"
DoCmd.OpenReport stDocName, acPreview

Exit_Command95_Click:
Exit Sub

Err_Command95_Click:
MsgBox Err.Description
Resume Exit_Command95_Click

End Sub
Private Sub Command96_Click()
On Error GoTo Err_Command96_Click
Application.FollowHyperlink "C:\Documents and Settings\john muir\My
Documents\bio - jm2"

Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Exit_Command96_Click:
Exit Sub

Err_Command96_Click:
MsgBox Err.Description
Resume Exit_Command96_Click

End Sub
 
jmuirman said:
I get an error : "Doc can't be found"

Here's my code - do i have it in the right place?

Intead of posting ALL of the code from your form how about posting just the code
from the button in question? I assume it is this...

**CODE START**
Private Sub Command96_Click()

On Error GoTo Err_Command96_Click
Application.FollowHyperlink "C:\Documents and Settings\john muir\My
Documents\bio - jm2"

Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

Exit_Command96_Click:
Exit Sub

Err_Command96_Click:
MsgBox Err.Description
Resume Exit_Command96_Click
End Sub
** CODE END**

Why did you add these three lines?

Dim oApp As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True

They are not necessary unless you want to control the Word Document from your
code. Your original post only asked about "opening a doc file". All you need
for that is the FollowHyperlink command.
 
Back
Top