Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a word document through Access!

Status
Not open for further replies.

rsmith64

MIS
Jun 20, 2002
27
0
0
US
I would like to have Access open a Word document with the click of a form button, and insert the data onto the page using a query that I have created.

How do I go about doing this? I can only get Access to open Word itself right now...
 
add a reference to the "Microsoft Word 8.0 Object Library"

and there you go:

Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objRange As Word.Range
Set objWord = New Word.Application
'Set objWord = GetObject(, "Word.Application") ' to use an existing word session
Set objDoc = objWord.Documents.Add("""YourWordTemplate.dot""") ' open a new document using a template
Set objRange = objDoc.Goto(What:=wdGoToBookmark, Name:="TheNameOfTheBookMark") ' go to a bookmark
If objRange Is Nothing Then
' bookmark not found
Else
objRange.Text = "This used to be a bookmark"
End If
objWord.PrintOut
objWord.ActiveDocument.Close False ' this closes the document WITHOUT saving
objWord.Quit
Set objWord = Nothing ' clean up all garbage
Set objDoc = Nothing
Set objRange = Nothing


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top