S
Steve Commisso
I'm using VBA on an Access form to open up Microsoft Word and pull a
MailMerge from a parameter query. I have the mail merge working fine. The
only problem is that when Word 2003 opens up and runs the mail merge, it
opens up ANOTHER copy of MS Access. This is causing a problem because the
parameter query is pulling a value from an Access form. However, when Word
opens up the 2nd copy of the Access database, that instance of Access does
not have the form opened to pull the parameter from. So, it's presenting the
user with a dialog box to enter the parameter (named for the form's field)
instead of just pulling the data.
Is there any way to avoid this? Here's my code:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge template>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="QUERY <queryname>", _
SQLStatement:="Select * from [<queryname>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
Instead of using the NAME argument for the OpenDataSource function, is there
a way to specify that OpenDataSource uses a currently open instance of
Microsoft Access? Or is there another way to solve the problem?
Thanks,
MailMerge from a parameter query. I have the mail merge working fine. The
only problem is that when Word 2003 opens up and runs the mail merge, it
opens up ANOTHER copy of MS Access. This is causing a problem because the
parameter query is pulling a value from an Access form. However, when Word
opens up the 2nd copy of the Access database, that instance of Access does
not have the form opened to pull the parameter from. So, it's presenting the
user with a dialog box to enter the parameter (named for the form's field)
instead of just pulling the data.
Is there any way to avoid this? Here's my code:
Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("<path to mail merge template>", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Northwind database.
objWord.MailMerge.OpenDataSource _
Name:="<path to access database>", _
SubType:=wdMergeSubTypeWord2000, _
LinkToSource:=True, _
Connection:="QUERY <queryname>", _
SQLStatement:="Select * from [<queryname>]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function
Instead of using the NAME argument for the OpenDataSource function, is there
a way to specify that OpenDataSource uses a currently open instance of
Microsoft Access? Or is there another way to solve the problem?
Thanks,