In place of
wd.Windows("merge_ad.doc ").Activate
wd.ActiveWindow.Close 0
use
wdActiveDoc.Close wdDoNotSaveChanges
Note, you do not show that you have declared wdActiveDoc as a document
object.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Kathy Webster"
news:474f0729$0$2338$4c368faf@roadrunner.com...
>I am collecting info from an MSAccess record and trying to merge it in
>Word. I would like this to work with any version of Word that the user may
>have installed. My MSAccess app will be a runtime app that I will be
>putting on various machines in different workplaces.
> Here is the code I am running from MSAccess:
>
> Public Function AddressBlock() As Boolean
>
> Dim wd As Object
> Dim wdActiveDoc As Object 'RM: Added this to help ensure that you're
> 'working on the document you intend to.
> Dim wdField As Object 'RM: Note the change in name here to avoid
> 'ambiguity with the Field object in both Word and
> 'Access. As well, I changed the type, since
> '(like Word.Application), you have to use late
> 'binding.
>
> Set wd = CreateObject("Word.Application")
> wd.Visible = True
>
> wd.Application.ScreenUpdating = False
>
> Set wdActiveDoc = wd.Documents.Open("K:\legalper\merge_ad.doc ", False,
> False, _
> False, "", "", False, "", "", 0)
>
> With wdActiveDoc.MailMerge
> .Destination = 0
> .Execute
> End With
> wd.Windows("merge_ad.doc ").Activate
> wd.ActiveWindow.Close 0
> 'It bombs here with "Automation error: The object invoked has disconnected
> from its clients", and the next line is highlighted.
> 'What I'm trying to do here is open merge_ad.doc, merge it, close
> merge_ad.doc, then save the
> 'resulting merged doc as "merged_ad.doc"
> wdActiveDoc.saveas Filename:="K:\legalper\merged_ad.doc",
> FileFormat:=0
>
> Thanks in advance,
> Kathy
>