View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Word mailmerge question

If I understood correctly what you are trying to do, I think it will be hard
to do it reliably precisely because the user can change the display names in
your application, unless your application always redefines the relationship
between the display name and the (presumably) fixed internal name each time
the user /uses/ a template. The only thing that I think comes close is what
I suggested before, i.e.
a. generate your data source file using your internal names (LastNm) etc.
b. dynamically generate the necessary SQL using the user-defined names and
use it in the OpenDataSource call. That will only work in this case if the
OpenDataSource call opens the text file using Jet SQL (not Word's very
simple built-in SQL dialect), which probably means you have to open the file
using an ODBC DSN, e.g. (in VBA) for a file called c:\a\abc.txt, something
like

ActiveDocument.MailMerge.OpenDataSource _
Name:="", _
Connection:= "DSN=Delimited Text
Files;DBQ=C:\a;DefaultDir=C:\a;DriverId=27;FIL=tex t;", _
SQLStatement:="SELECT Code As `display name for code`,FirstNm As `Display
name for FirstNm FROM abc.txt", _
SubType:=wdMergeSubTypeWord2000

(you only need the last parameter in Word XP and later)

Peter Jamieson



wrote in message
ups.com...
I'm not sure how I can use this. My application generates a datasource
(textfile) in the format:
"Code","First Name","Last Name"
When the user creates the Mailmerge Template he sees those names
instead of ID,FirstNm,LastNm. The template will then have the
mergefield: Last_Name
Now has the user the option to change the displayname of this field
i.e. he changes it in "Name", the next time he tries to generate the
document the datasource will have the following headers:
"Code","First Name","Name" so the field Last_Name gives an error. Is
it possible to show the user Last_Name but internally store LastNm?

My datasource is created by a Delphi application and linked using:

aMergeDoc.MailMerge.OpenDataSource(aFN, ....);
where aMergeDoc: _Document and aFN is the filename of the txt file.

Jos