Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

IN THIS TASK

Summary

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 File

Sort 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 Document

NOTE: <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:

  1. Open a new blank document, and then on the Tools menu, click Mail Merge.

  2. In the Mail Merge Helper, click Create, and then click Catalog.

  3. Click New Main Document when prompted.

  4. In the Mail Merge Helper, click Get Data, and then click Open Data Source to attach the data file (use the sample file that you created in the "How to Set Up the Data File" section of this article).

  5. 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.

NOTE: This example uses the sample data from the "How to Set up the Data File" section of this article. To insert the field braces, press CTRL+F9.


{ IF { MERGESEQ } = "1" "{ MERGEFIELD City }" "" }<ENTER>
{ 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>
The fields laid out in this example produce a catalog listing on the same page, as follows:

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 Page

The 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>
{ 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>
NOTE: To insert a page break, either press CTRL+ENTER, or click Break on the Insert menu, select Page Break, and then click OK.

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 Field

The 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>
{ 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>
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:

ATLANTA

Smith $3,000
Gates $50,000
Henderson $10,000

HOUSTON

Jones $8,000
Kelley $9,000
Peterson $0
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.


How This Process Works

The 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.

References

For 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 HOW TO: Design and Set Up Mail Merge Data in Microsoft Word 2000

212329 WD2000: How to Use Mail Merge to Create a Form Letter

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×