WD: How to Merge Conditional Number of Records to the Same Page

ID: Q189024

The information in this article applies to:

SUMMARY

In Microsoft Word, you can merge a conditional number of records to the same page.

MORE INFORMATION

To merge a conditional number of records to the same page, use a combination of SET, IF, and NEXTIF fields. For example, you could use this method to merge all records with the same name to one page in the merge and create a new page in the merge when a new name is encountered in the data file.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this field code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following example uses a data file with employee names (Employee) and projects they are working on (Projects). The Check field is used in the data file to mark the last record of a particular name.

Sample Data File:

   Employee     Project     Check
   John Doe     4578j
   John Doe     86785x
   John Doe     543p          1
   Jane Doe     87x
   Jane Doe     89976m        1
   Sam Smith    7897r
   Sam Smith    857t
   Sam Smith    78974x
   Sam Smith    7868p         1

The main document should be set up as follows, with a copy of the conditional statements equal to the maximum number of projects for each employee (four in the above example).

   Employee     Project
   {MERGEFIELD Employee}     {MERGEFIELD Project}{set duplicate {if
   {MERGEFIELD Check}="1" "off" "on"}}{nextif {mergefield check}=""}{if
   {duplicate}="on" "P
   t{MERGEFIELD Project}"}{set duplicate {if {MERGEFIELD Check}="1"
   "off" "on"}}{nextif {mergefield check}=""}{if {duplicate}="on" "P
   t{MERGEFIELD Project}"}{set duplicate {if {MERGEFIELD Check}="1"
   "off" "on"}}{nextif {mergefield check}=""}{if {duplicate}="on" "P
   t{MERGEFIELD Project}"}{set duplicate {if {MERGEFIELD Check}="1"
   "off" "on"}}{nextif {mergefield check}=""}{if {duplicate}="on" "P
   t{MERGEFIELD Project}"}

Where "P" represents a paragraph mark that would push the next Project to a new line and "t" represents a tab character that would align the next project under the previous project.

The resulting merge document would appear as follows:

   Employee     Project
   John Doe     4578j
                86785x
                5436435p
   --- Page Break ---
   Jane Doe     87x
                89976m
   --- Page Break ---
   Sam Smith    7897r
                857t
                78974x
                7868p

Additional query words: catalog index list table print merge mail merge
Keywords          : kbdta wordnt kbfield winword kbmerge ntword macword word6 winword2 word7 word95 
Version           : MACINTOSH:6.0,6.0.1,6.0.1a; WINDOWS:2.0,2.0a,2.0a- CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; WINNT:6.0
Platform          : MACINTOSH WINDOWS
Issue type        : kbhowto

Last Reviewed: February 13, 1999