Access.2007.VBA.Bibl..

(John Hannent) #1

Part II Writing VBA Code to Exchange Data between Office Components


Using Word Field Switches to Format Text


Data in DocProperty Fields


W


hen you use Word document properties to merge Access data to Word documents, the values
written to the document properties are displayed on the Word document in DocProperty
fields. You can use field switches to format the data displayed in the DocProperty field in a variety of
ways, which is going to be necessary if you follow my advice and use mostly (if not exclusively) Text
document properties. The field switches needed to produce some commonly used formats are listed
in the following table.

Raw Access Data Desired Word Format Field Code Switches

11523.75 $11,523.75 DOCPROPERTY “DollarAmount” \#
$###,##0.00
2/2/2001 February 2, 2001 DOCPROPERTY “DueDate” \@
“MMMM d, yyyy”
282839898 28283-9898 DOCPROPERTY “ZipCode” \# “00000’-
’0000”
829887445 829-88-7445 DOCPROPERTY “SSN” \# “000’-’00’-
’0000”
150250.50 one hundred fifty thousand DOCPROPERTY “DollarAmount” \*
two hundred fifty and 50/100 DollarText
150250.25 ONE HUNDRED FIFTY THOUSAND DOCPROPERTY “DollarAmount” \*
TWO HUNDRED FIFTY AND 25/100 DollarText \* Upper
150250.50 one hundred fifty thousand DOCPROPERTY “EntryAmount” \*
two hundred fifty CardText
11/13/2005 Thirteenth DOCPROPERTY “StartDate” \@ “d” \*
OrdText \*FirstCap
11/13/2005 November DOCPROPERTY “StartDate” \@
“MMMM”

You can create PostNet bar codes for U.S. zip codes on an envelope or label by
adding a ZipCode DocProperty field to the Word template and applying a ZipCode
bookmark to it. Because the WholeAddress field includes the zip code (or postal code, depending
on the country), you should make the ZipCode DocProperty field invisible. To do this, select the
field, open the Font Dialog by clicking the tiny arrow in the lower right of the Font group on the
Word Ribbon, and check the Hidden checkbox. Next, position your cursor above the address block,
select Insert➪Quick Parts➪Field, select the BarCode field, and then the ZipCode bookmark;
leave the POSTNET bar code checkbox checked, and click OK to insert the bar code field (see the
next figure).

TIPTIP

Free download pdf