View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Entering parameter value in a mail merge

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

"JimAA" wrote in message
...
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.