WD: Using Print Merge to Create a List Sorted by Category

Last reviewed: February 23, 1998
Article 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:

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

  2. 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:

    a. For this method to work properly, information other than the

          above fields must be entered in the header or footer of the main
          document.
    

    b. "<paragraph mark>" means you should press ENTER to insert a

          paragraph mark.
    

    c. The first SET field assigns the current city name to the

          bookmark Place1.
    

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

    e. 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:

    a. Activate the FormLetters1 document.

    b. From the Edit menu, choose Replace.

    c. In the Find What box, type "^12" (without the quotation marks).

    d. Clear the contents of the Replace With box.

    e. Choose the Replace All button.

    f. 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 : kbfield kbhowto kblayout kbmerge winword winword2 word6 word kbusage
    Version : 2.0 2.0a 2.0a-CD 2.0b 2.0c 6.0 6.0a 6.0c
    Platform : WINDOWS


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: February 23, 1998
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.