Runtime Error 4605: Word MailMerge automation

T

Todd Lemen

I am using Access 2k3 to automate letterwriting (statements and invoices).
I have a word document built as a mail merge base file. It's data source is
linked to a Jet/ODBC oject stored in a sprcified location. The data source
is an MS Access 2k3 .mdb file bearing only tables for mail merges. The main
Access application carries links to these tables. QueryDefs in the main
application execute to populate these tables.

When I open the Word document, it tells me it will pull data from the .odc
file, and executes the mail merge properly. No problem. When I execute the
same from the main Access application, I ge Run-time error 4605:"This method
or property is not available because the document is not a mail merge main
document." Well. Yes it is... It runs as expected in Word 2K3...

OK. So, here's the code used to drive the mail merge from Access:
Dim appWord as New Word.Application
Dim docLetters As Word.Document
Dim qd as QueryDef
...........................
Set qd = db.QueryDefs!AppendStatementsReport
qd.Execute
Set qd = Nothing
Set docLetters = appWord.Documents.Open("C:\VMed\Statement2.doc")
appWord.Visible = True
docLetters.MailMerge.Execute
docLetters.Close

Error 4605 occurs at "docLetters.MailMerge.Execute"

Suggestions?
Thanks,
TL
 
T

Todd Lemen

In this case, the problem was a failure of Word to connect to its data source
when executing mail merge from VBA commands. Here is replacement code that
works. (I have a couple of notes marked as comment lines). This replacement
codes is used afer QueryDef populates data table:

Set docLetters = appWord.Documents.Open("C:\VMed\Statement2.doc",
False, False, False, "", "", False, "", "", wdOpenFormatAuto, "", True)

'The next line explicily opens and assigns the data source to the
mail merge document opened as an app object in Access. The line after next
makes the Word Application object visible. Even though the Word Application
Document object is opened with visibility set to true, the object's
visibility property must be set to true in order for user to see Word.

docLetters.MailMerge.OpenDataSource ("F:\Clerk\Data
Sources\StatementsReportTable.odc")
appWord.Visible = True
With docLetters.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
docLetters.Close (wdDoNotSaveChanges)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top