RegionsRob
Programmer
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
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