Entering parameter value in a mail merge

J

JimAA

I have a Word template that uses an Access query with a parameter. When I
open the template to create a new document I get a dialog box that asks for
the parameter data. After entering the data I get the same dialog box asking
for the same parameter data. I'm assuming that I get a dialog box when the
template is opened and when the new document is opened.
Is there a way to avoid having to enter the same parameter data twice?
Thanks.
 
P

Peter Jamieson

Yes, this problem seems to occur in Word 2002 and later. I think the only
solution is to change the template so that it is not attached to the data
source, and use an AutoNew macro to open the data source when the new
document based on the template is created.

e.g. something like

Sub AutoNew()

Dim strPathName As String
Dim strConnect As String
Dim strQuery As String

' Put the pathname of your Access .mdb
strpathName = "c:\mydbs\mydb.mdb"

' Construct the Connect string

strConnect = "QUERY myquery"

' Construct the Query - you may also need WHERE and ORDER BY
' clauses for filtering and sorting

strQuery = _
"SELECT * FROM `myquery`"

' The following should be enough in Word 2003
' If you do not need WHERE clauses etc. you
' can delete the SQLStatement line

ActiveDocument.MailMerge.OpenDataSource _
Name:=strPathName, _
Connection:=strConnect, _
SQLStatement:=strQuery, _
Subtype:=wdMergeSubTypeWord2000

' Set the merge type you want
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters

' optionally set the destination you want
ActiveDocument.MailMerge.Destination = wdSendToNewDocument

End Sub

Peter Jamieson
 

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