How do I make a button to open a specific Word doc?

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

Guest

How do I make a button to open a specific Word doc? I want to hit a button on
my form to open a a specific word document...

Thanks,

John
 
To open a word document, create reference to Microsoft Word and then

Function Open_WordDoc()

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim DocPath As String

DocPath = "Path and name of the document"

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open(DocPath)

objDoc.Activate
objDoc.PrintOut ' To print out
objWord.Visible = True ' To display

End Function
===========================
Or use the FollowHyperLink

Dim DocLocationAndName as String
DocLocationAndName = "C:\FileName.Doc"
application.FollowHyperlink DocLocationAndName
 
You can simply use the FollowHyperlink method like:

Application.FollowHyperlink "FullPathNameOfYourDoc"
 
With either method above, where do I start - do I paste code somewhere or is
there a wizard of some kind?

Thanks,

John
 
Yes you can paste this code to the OnClick event of the button, just change
the name of the Doc File.
If you get any error, post the code you are using and specify how do you get
the name of the Document
--
If I answered your question, please mark it as an answer. That way, it will
stay saved for a longer time, so other can benifit from it.

Good luck
 
I got several messages - I probably pasted in the wrong spot - here's the code:

End Sub
Private Sub Command76_Click()
On Error GoTo Err_Command76_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FNewCases-BY CLAIMANT"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command76_Click:
Exit Sub

Err_Command76_Click:
MsgBox Err.Description
Resume Exit_Command76_Click

End Sub
Private Sub Command77_Click()
Function Open_WordDoc(C:\Documents and Settings\John Muir\My
Documents\LETTER-TEMPLATE ALL PARTIES TO LOSS.doc)

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim DocPath As String

DocPath = "Path and name of the document"

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open(DocPath)

objDoc.Activate
objDoc.PrintOut ' To print out
objWord.Visible = True ' To display

End Function

Thanks,

John
 
Have you created a reference to Microsoft word?
Open code (any where) select Tools > reference > add from the list Microsoft
word

About the code, try this

Private Sub Command77_Click()
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim DocPath As String

DocPath = "C:\Documents and Settings\John Muir\My Documents\LETTER-TEMPLATE
ALL PARTIES TO LOSS.doc"

Set objWord = New Word.Application
Set objDoc = objWord.Documents.Open(DocPath)

objDoc.Activate
objDoc.PrintOut ' To print out
objWord.Visible = True ' To display

End Sub
 
Back
Top