
Mail merge error: Access 97 to Word 97
I'm trying to duplicate the "solution" in KB#131583 (sending
the current record to word with automation). The first time I
execute the code, Word gets started, document opens, merge takes
place (I made it a merge doc) and it prints. (Is there any way to
specify the # copies on a mail merge? sendkeys??). Anyway it works
fine.
The second time I execute it, Word opens, then opens the document but
fails on the Mail Merge stmt with the following error:
Runtime error '-2147023174(800706ba)'
automation error RPC Server is unavailable
I've also noticed that after the first execution, if I click on
"Reset" fron the Run menu in Access prior to re-running the code,
it works every time. Here's the code:
Public Sub mergeit()
Dim objword As Word.Application
Set objword = CreateObject("word.application")
With objword
.Visible = True
.Documents.Open ("v:\winword8\welco.doc")
End With
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
objword.ActiveDocument.PrintOut Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=3, Pages:="",
PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False
objword.ActiveDocument.Close savechanges:=wdDoNotSaveChanges 'close
merged doc
objword.ActiveDocument.Close savechanges:=wdDoNotSaveChanges 'close
original doc
objword.Quit
Set objword = Nothing
End Sub
Thanks for any help.
Paul Honore