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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated Mail Merge from Access

Status
Not open for further replies.

RegionsRob

Programmer
Oct 18, 2001
50
US
Can someone help me finish what MS KnowledgeBase started? Article Q159328 has code that opens the merge document in Word and executes the merge. They do not then do the next logical step of DESTROYING the instance of Word. I have added code to close and quit Word, but the Word window does not fully destroy itself until I click on the Access window.
What have I done wrong/what am I leaving out?

Function MergeIt()
DoCmd.Hourglass True
Dim objWord As Word.Document
Dim DocPath As String
DocPath = "S:\ApprovedAppraiserLetter.doc"
Set objWord = GetObject(DocPath, "word.document")
'make Word visible
objWord.Application.Visible = True
'set mail merge data source
objWord.mailmerge.opendatasource _
name:="s:\databases\appraisers.mdb", _
linktosource:=True, _
Connection:="query qryAddUpTMOAddOnly"
'execute mail merge
objWord.mailmerge.Destination = wdSendToNewDocument
objWord.mailmerge.Execute
With objWord.Application
.ActiveDocument.PrintOut Background:=False
.ActiveDocument.Close _
savechanges:=wdDoNotSaveChanges
End With
objWord.Application.Quit savechanges:=wdDoNotSaveChanges
Set objWord = Nothing
DoCmd.Hourglass False
End Function
 
objWord.Application.Visible = False

This will kill word for you.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top