WD95: Using Mail Merge to Create a List Sorted by Category

This article has been archived. It is offered "as is" and will no longer be updated.
Summary
You can use the Mail Merge feature in Word to create a list of data sortedand separated by a category. This article contains instructions and asample you can use to create such a list.
More information

Setting Up the Data File

Sort your data file so that all records with the same value for the keyfield (category--the field upon which you base the sort) are together, asshown in the sample data file below. The following sample list is sorted bythe 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				

Setting Up the Main Document

NOTE: A Paragraph Mark in the following example is designated as <P>. Donot type the <P>, instead press ENTER.

To set up your main document as a Catalog, follow these steps:
  1. From a new blank document, click Mail Merge on the Tools menu.
  2. In the Mail Merge Helper, click the Create button 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 file you created in the "Setting 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 "Setting up the data file" section of this article.
    {If{MergeSeq} = "1" "{Mergefield City}<P>
    " ""}{Set Place1 {Mergefield City}}<P>
    {If{Place2}<>{Place1}"<P>
    {Mergefield City}<P>
    <P>
    {Mergefield Employee}{Mergefield Sales}" "{Mergefield
    Employee}{Mergefield Sales}"}{Set Place2{Mergefield City}}<P>
    The fields laid out in this example will 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

Forcing Each New Category to a New Page

The key field in this example is {Mergefield City}. When the value of Citychanges in the data file to a different city, then a new page is added tothe merged results and the merge is continued at the top of the next page.
{If{MergeSeq} = "1" "{Mergefield City}<P>
" ""}{Set Place1 {Mergefield City}}<P>
{If{Place2}<>{Place1}"
----------------------------Page Break--------------------------------
{Mergefield City}<P>
<P>
{Mergefield Employee}{Mergefield Sales}" "{Mergefield
Employee}{Mergefield Sales}"}{Set Place2{Mergefield City}}<P>
NOTE: A page break is inserted either by pressing CTRL+ENTER or clickBreak on the Insert menu, select Page Break and then click OK.

The fields laid out in this example will produce a catalog listing onseparate pages as follows:
Atlanta

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

----------------------------Page Break--------------------------------

Houston

Jones $8,000
Kelley $9,000
Peterson $0

To Format the Key Field



The key field in this example is {Mergefield City}. To format the resultsof the {Mergefield City} as all capital letters, you can use the formattingswitch of \* Upper.
{If{MergeSeq} = "1" "{Mergefield City \* Upper}<P>
" ""}{Set Place1 {Mergefield City}}<P>
{If{Place2}<>{Place1}"<P>
{Mergefield City \* Upper}<P>
<P>
{Mergefield Employee}{Mergefield Sales}" "{Mergefield
Employee}{Mergefield Sales}"}{Set Place2{Mergefield City}}<P>
The fields laid out in this example will produce a catalog listing on thesame page with the City in all capital letters as follows:
ATLANTA

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

HOUSTON

Jones $8,000
Kelley $9,000
Peterson $0
For more information about general field formatting switches, clickMicrosoft Word Help Topics on the Help menu, click the Index tab in "HelpTopics: Microsoft Word," type the following text
fields, formatting
and then double-click the selected text to go to the "General Switches"topic.

NOTE: You can apply different formatting to the key field {Mergefield City}by selecting the entire field (including the field braces { }) andformatting the field as desired. To format the field, click Font on theFormat menu.
References
For additional information, please see the following article in theMicrosoft Knowledge Base:
141922 WD: How to Start a Mail Merge
invoice catalog phone directory conditional
Properties

Article ID: 181729 - Last Review: 01/12/2015 15:59:39 - Revision: 2.0

Microsoft Word 95a

  • kbnosurvey kbarchive kbfield kbformat kbhowto kblayout kbmerge KB181729
Feedback