Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
 
Posts: n/a
Default Word mailmerge question

Hi,

I'm trying to figure out how to best use word mailmerge from my
application. In my application there is a difference in the Display
name of a field and the fieldname in the database. I want the user to
be able to use the (user-friendly) displayname when creating the merge
template, but when I use the displayname as the fieldcode I will run
into problem when the user changes the displayname inside my
application. So is it possible to show the user the Displayname when he
is creating the template, but internaly in the mailmerge template to
use the dbfieldname in the fieldcode?

Jos.

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

Typically the best way to do this, if your data source allows it, is to
define a Query (or View) based on the table you want to use, and give the
columns of the View/Query the names you want the user to see.Then use the
query/view as the data source for the merge.

Typically the Query/View just defines an alias for each column in SQL, along
the lines of

SELECT column1 As `username1`, column2 As `username2` FROM table1

In some cases you may be able to do that by issuing the appropriate SQL in
Word's OpenDataSource method call rather than by creating a Query/View in
Access/SQL Server or whatever, but only if
a. the dialect of SQL supports it
b. the SQL statement is not too long (there's a limit of around 255/511
characters, depending on the data source and connection type).



Alternatively if you are opening the datasource in VBA code in some cases
you may be able to do this
wrote in message
oups.com...
Hi,

I'm trying to figure out how to best use word mailmerge from my
application. In my application there is a difference in the Display
name of a field and the fieldname in the database. I want the user to
be able to use the (user-friendly) displayname when creating the merge
template, but when I use the displayname as the fieldcode I will run
into problem when the user changes the displayname inside my
application. So is it possible to show the user the Displayname when he
is creating the template, but internaly in the mailmerge template to
use the dbfieldname in the fieldcode?

Jos.



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
 
Posts: n/a
Default Word mailmerge question

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

  #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



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 97 in Windows XP to maintain formatting Charlie''s Word VBA questions Microsoft Word Help 22 May 20th 23 08:51 PM
Does Word have a QuickCorrect/Quick Word option like WordPerfect? CW New Users 2 December 20th 05 06:54 PM
In Word, how do I surpress headers and footers on page 2 Bill Microsoft Word Help 1 December 15th 05 07:13 PM
Templates vs. Macros - what is the best route for law office? trazpup Microsoft Word Help 5 July 18th 05 06:10 PM
is word perfect compatible with office word? Noreen Microsoft Word Help 1 May 11th 05 11:17 PM


All times are GMT +1. The time now is 02:10 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"