Mail merge from ACCESS to Word
Hi Gang -
I have a database that I need to force to execute a mail merge to word from. I am no VB programmer by any means and scoured the web for some code. When it runs it seems to want to open a new version of the database instead of the existing (open) one. It needs to run from the open database as a user must login to the database and its server to have rights to the data.
Any ideas???
Function MEDCART()
'Dim objWord As Word.Document
Set objWord = GetObject("C:\rxlabels.doc", "Word.Document")
' Make Word visible.
objWord.APPLICATION.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\SMS\PCW\I86\23060031\bin\" & _
"UDARPT.mdb", _
LinkToSource:=True, _
Connection:="Table INPATS", _
SQLStatement:="SELECT * FROM [inpats]"
' Execute the mail merge.
'objWord.MailMerge.Execute
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.APPLICATION.Options.PrintBackgro und = False
objWord.APPLICATION.ActiveDocument.Print Out
End Functionmfo.,y
Thanks in advance
I have a database that I need to force to execute a mail merge to word from. I am no VB programmer by any means and scoured the web for some code. When it runs it seems to want to open a new version of the database instead of the existing (open) one. It needs to run from the open database as a user must login to the database and its server to have rights to the data.
Any ideas???
Function MEDCART()
'Dim objWord As Word.Document
Set objWord = GetObject("C:\rxlabels.doc", "Word.Document")
' Make Word visible.
objWord.APPLICATION.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Program Files\SMS\PCW\I86\23060031\bin\" & _
"UDARPT.mdb", _
LinkToSource:=True, _
Connection:="Table INPATS", _
SQLStatement:="SELECT * FROM [inpats]"
' Execute the mail merge.
'objWord.MailMerge.Execute
objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute
'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.
objWord.APPLICATION.Options.PrintBackgro
objWord.APPLICATION.ActiveDocument.Print
End Functionmfo.,y
Thanks in advance
