Running the code below, I get an error in Word displayed on a blank document. (field calculation error in record 1) If I manually execute the merge in Word from the same query it works fine. Obviously there is something wrong with the code. The code is a slightly modified version of code I got from a knowledgebase article. The modification changes the module to a sub instead of a function and allows me to pass the document name to it.
Public Sub MergIt(docObj As String)
Dim objWord As Word.Document
Set objWord = GetObject(docObj, "Word.Document")
'make word visible
objWord.Application.Visible = True
'set data source
objWord.MailMerge.OpenDataSource NAME:="c:\Sales_dev\mysales.mdb", _
LinkToSource:=True, Connection:="QUERY mail_list", _
SQLStatement:="Select * from [mail_list]"
objWord.MailMerge.Execute
objWord.MailMerge.Destination = wdSendToNewDocument
End Sub
Public Sub MergIt(docObj As String)
Dim objWord As Word.Document
Set objWord = GetObject(docObj, "Word.Document")
'make word visible
objWord.Application.Visible = True
'set data source
objWord.MailMerge.OpenDataSource NAME:="c:\Sales_dev\mysales.mdb", _
LinkToSource:=True, Connection:="QUERY mail_list", _
SQLStatement:="Select * from [mail_list]"
objWord.MailMerge.Execute
objWord.MailMerge.Destination = wdSendToNewDocument
End Sub