Normal Topic Using MS-Word switches to format merge fields (Read 546 times)
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Using MS-Word switches to format merge fields
Feb 3rd, 2004 at 8:08pm
Print Post Print Post  
There have been a number of postings from folk having trouble with database values being printed in Microsoft Word documents 'unformatted'. That is, with extra decimal places or dates in YYYY/MM/DD format.  A number of solutions have been offered.

The solution, though, lies outside of Sesame. It's to use Word's field switches.

Firstly, in your merge document, show the field code rather than the result. To do this click on the field and press Shift F9, or press Alt F9 to toggle all field codes.

Click at the end of the field code and add the appropriate switch.  For example, change ..

{MERGEFIELD Date}
to
{MERGEFIELD Date \@ "MMMM dd, yy"}

Where "Date" is the column heading ("field name") of the field in question. The field code starts with the \ character.

By this means you can vary the number of decimal places for numbers, format dates any way you want, and turn numbers into currency amounts.  Here are some examples...

Dates

\@ "MM/dd/yyyy"     produces         11/19/2003
\@ "MM-dd-yy"      produces         11-19-03
\@ "dd MMM yy"      produces         19 Nov 03
\@ "dddd, MMMM d, yyyy"   produces    Wednesday, November 19, 2003

Numbers & Currency
     
Example = 1237.852941

\#0.00      produces  1237.85
\#0      produces             38
\#$#,###.00      produces      $  1,237.85
\#£#,###      produces      £  1,238


Text

\* Upper      produces  NY  from "ny"
\* Caps    produces   New York  from "new york"

Once you've set the field code, press Shift F9 to display the value again. Don't be alarmed - it will still show the previous formatting. Press F9 to 'refresh' the field.

This is described in the Programming Guide pages 242-243.
« Last Edit: Feb 5th, 2004 at 12:01am by Alec »  

Alec
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Using MS-Word switches to format merge fields
Reply #1 - Feb 3rd, 2004 at 8:27pm
Print Post Print Post  
Thanks Alec, missed reading that part of documentation on page 242 -243.  We realized that changing the field format to text format was not the ultimate solution. This resolves the Wordmerge problem related to proper formating of Date, Number and Money fields for good. I hope PeterG would read this link.
  
Back to top
 
IP Logged