WD: Using Print Merge to Create a List Sorted by Category
ID: Q97795
|
The information in this article applies to:
-
Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
SUMMARY
You can use the Print Merge command in Word for Windows to create a list of
data sorted by category. This article contains instructions and a sample
you can use to create such a list.
MORE INFORMATION
Use the following procedure to create a list of items sorted by category:
- Sort your data file so that all records with the same value for the
key field (the field upon which you base the sort) are together, as
shown in the sample data file below. The following sample list is
sorted by the CITY field (CITY is the key field):
CITY EMPLOYEE SALES
Atlanta Smith $3,000
Atlanta Gates $50,000
Atlanta Henderson $10,000
Houston Jones $8,000
Houston Kelley $9,000
Houston Peterson $0
- In the main document, insert a SET field that assigns the key field
to a bookmark variable that you can use to compare the contents of
one key field record with the next. The following is the syntax of
the field you should insert:
{SET BookmarkName {MERGEFIELD KeyField}}
For example, insert the following SET field to assign the CITY key
field to the Place1 bookmark:
{SET Place1 {MERGEFIELD CITY}}
- In the main document, insert the following fields to compare the
contents of each key field record with the contents of the next key
field record to determine whether the key field contents change
from one data record to the next. These fields use the sample data
document in step 1 above.
{SET place1 {MERGEFIELD CITY}}
{IF{place2}<>{place1} "{MERGEFIELD City} <paragraph mark>
{MERGEFIELD Employee} {MERGEFIELD Sales}" "{MERGEFIELD Employee}
{MERGEFIELD Sales}"}
{SET place2 {MERGEFIELD CITY}}
Word Version 6.0
In order for the example above to work with Word 6.0, you must
replace the "{SET place1..." entry with:
{Set place1 {if {mergeseq} = 1 "" "{mergefield city}"}}
Notes for all versions:
- For this method to work properly, information other than the
above fields must be entered in the header or footer of the main
document.
- "<paragraph mark>" means you should press ENTER to insert a
paragraph mark.
- The first SET field assigns the current city name to the
bookmark Place1.
- The IF field comparison determines whether the CITY field is the
same as the previous CITY field. If the expression evaluates to
True (different city), the result is the City, Employee, and
Sales fields. If the expression evaluates to False (same city),
the result is the Employee and Sales fields.
- For the first record, the comparison evaluates to False because
the Place2 bookmark has not yet been assigned a value; as a
result, the City field prints. In each subsequent record, the
value for the previous CITY is held in the Bookmark Place2.
- Choose the Merge To New Document button on the print merge bar.
- To complete your categorized list, remove the page breaks from the
FormLetters1 merged document, as described below:
- Activate the FormLetters1 document.
- From the Edit menu, choose Replace.
- In the Find What box, type ^12.
- Clear the contents of the Replace With box.
- Choose the Replace All button.
- Choose the Close button. The resulting list appears as follows:
Atlanta
Smith $3,000
Gates $50,000
Henderson $10,000
Houston
Jones $8,000
Kelley $9,000
Peterson $0
REFERENCES
"Microsoft Word for Windows User's Guide," version 2.0, pages 611-651
Additional query words:
invoice catalog phone directory conditional mail merge
Keywords : kbusage kbfield winword kbmerge kblayout word6 winword2 kbhowto word
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c
Platform : WINDOWS
Issue type :
|