Article ID: 211303 - Last Review: August 29, 2007 - Revision: 1.2 HOW TO: Use Mail Merge to Create a List Sorted by Category in Word 2000This article was previously published under Q211303 On This PageSUMMARY
You can use the Mail Merge feature in Microsoft Word to create a list of data sorted and separated by a given category. This article provides instructions and a sample that you can use to create such a list.
How to Set Up the Data FileSort your data file so that all records with the same value for the key field category (the field upon which you base the sort) appear together, as shown in the following sample data file. The following sample list is sorted by the City field (City is the key field in this example):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 How to Set Up the Main DocumentNOTE: <ENTER> designates a paragraph mark in the following example. To type a paragraph mark, press ENTER.To set up your main document as a catalog, follow these steps:
{ IF { MERGESEQ } = "1" "{ MERGEFIELD City }" "" }<ENTER>
The fields laid out in this example produce a catalog listing on the same page, as follows:
{ SET Place1 { MERGEFIELD City }}<ENTER> { If { Place2 } <> { Place1 }"<ENTER> { MERGEFIELD City }<ENTER> <ENTER> { MERGEFIELD Employee }{ MERGEFIELD Sales }" "{ MERGEFIELD Employee }{ MERGEFIELD Sales }" }{ SET Place2 { MERGEFIELD City }}<ENTER>
Atlanta Smith $3,000 Gates $50,000 Henderson $10,000 Houston Jones $8,000 Kelley $9,000 Peterson $0 How to Force Each New Category to a New PageThe key field in this example is { MERGEFIELD City }. When the value of City changes in the data file to a different city, a new page is added to the merged results, and the merge operation continues at the top of the next page. To insert the field braces, press CTRL+F9.{ If { MERGESEQ } = "1" "{ MERGEFIELD City }" ""}<ENTER> NOTE: To insert a page break, either press CTRL+ENTER, or click Break on the Insert menu, select Page Break, and then click OK.{ SET Place1 { MERGEFIELD City }}<ENTER> { If { Place2 } <> { Place1 }"<ENTER> ----------------------------Page Break-------------------------------- { MERGEFIELD City }<ENTER> <ENTER> { MERGEFIELD Employee }{ MERGEFIELD Sales }" "{ MERGEFIELD Employee }{ MERGEFIELD Sales }" }{ SET Place2 { MERGEFIELD City }}<ENTER> The fields laid out in this example produce a catalog listing on separate pages as follows:
Atlanta Smith $3,000 Gates $50,000 Henderson $10,000 ----------------------------Page Break----------------------------- Houston Jones $8,000 Kelley $9,000 Peterson $0 How to Format the Key FieldThe key field in this example is {MERGEFIELD City}. To format the results of the {MERGEFIELD City} as all capital letters, you can insert the formatting switch of \* Upper. To insert the field braces, press CTRL+F9.{ If { MERGESEQ } = "1" "{ MERGEFIELD City \* Upper }" "" }<ENTER>
The fields laid out in this example produce a catalog listing on the same page, with the city appearing in all uppercase letters, as follows:
{ SET Place1 { MERGEFIELD City }}<ENTER> { IF { Place2 } <> { Place1 }"<ENTER> { MERGEFIELD City \* Upper }<ENTER> <ENTER> { MERGEFIELD Employee }{ MERGEFIELD Sales }" "{ MERGEFIELD Employee }{ MERGEFIELD Sales }" }{ SET Place2 { MERGEFIELD City }}<ENTER>
ATLANTA NOTE: You can apply different formatting to the key field, { MERGEFIELD City }, by selecting the entire field (including the field braces { }), and formatting the field to your preferences. To format the field, click Font on the Format menu.
Smith $3,000 Gates $50,000 Henderson $10,000 HOUSTON Jones $8,000 Kelley $9,000 Peterson $0 How This Process WorksThe first IF field in these examples inserts the city name and a return character (<ENTER>) only for the very first record in the mail merge. For all subsequent records, this IF field inserts nothing (""). It recognizes the first mail-merge record by comparing the MERGESEQ field (which returns the sequence number for the current record) to the numeral "1".The second IF field inserts a return character (or a page break, if it forces each city to a new page), the city name, two more return characters, the employee name, and the sales amount (in that order), only if the IF field determines that the current record includes a city name that is different from the preceding record. If it determines that the current record includes a city name that is the same as the preceding record, it inserts only the next employee name and sales amount. This IF field recognizes the new city name by comparing the text of the bookmarks specified in the two SET fields. The text of the bookmark "Place1" is always equal to the current record's City field, and the text of the bookmark "Place2" is equal to the preceding record's City field. REFERENCESFor more information about IF fields, click Microsoft Word Help on the
Help menu, type Field Codes: IF field in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned. For more information about MERGESEQ fields, click Microsoft Word Help on the Help menu, type Field Codes: MERGESEQ field in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned. For more information about SET field, click Microsoft Word Help on the Help menu, type Field Codes: SET field in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned. For more information about general field formatting switches, click Microsoft Word Help on the Help menu, type general switches in the Office Assistant or the Answer Wizard, and then click Search to view the topic. For additional information about mail merges, click the article numbers below to view the articles in the Microsoft Knowledge Base: 212322
(http://support.microsoft.com/kb/212322/EN-US/
)
HOW TO: Design and Set Up Mail Merge Data in Microsoft Word 2000
212329
(http://support.microsoft.com/kb/212329/EN-US/
)
WD2000: How to Use Mail Merge to Create a Form Letter
| Article Translations
|
Back to the top
