The NEXTIF field compares two expressions. If the comparison is true, Microsoft Office Word merges the next data record into the current merge document. If the comparison is false, Word merges the next data record into a new merge document.

You can use the NEXTIF field to group data records, as in a database report. For example, you can use a combination of IF, SET, and NEXTIF fields to merge all records with the same postal code to one page in the merge and create a new page in the merge when a new postal code is encountered in the data file. However, a merge like this is complex to set up and requires that your data source be structured to accommodate the merge fields.

If your goal is to selectively include certain records from your data source, you can do this more easily by using the Filter command in the Mail Merge Recipients dialog box, which appears when you click Edit Recipient List in the Start Mail Merge group on the Mailings tab.

Notes:

Syntax

{ NEXTIF Expression1 Operator Expression2 }

Note To see the field codes in a main document, press ALT+F9. To see field results again, press ALT+F9 a second time.

showProperties

Expression1, Expression2

Values that you want to compare. These expressions can be merge field data, bookmark names, strings of characters, numbers, nested fields that return a value, or mathematical formulas. If an expression contains spaces, enclose the expression in quotation marks.

Notes:

  • If you use a merge field (MERGEFIELD) in an expression, the merge field refers to data in the current data record, not in the next data record.
  • Expression2 must be enclosed in quotation marks so that it is compared as a character string.
  • If the operator is = or <>, Expression2 can contain a question mark (?) to represent any single character or an asterisk (*) to represent any string of characters.
  • If you use an asterisk in Expression2, the portion of Expression1 that corresponds to the asterisk and any remaining characters in Expression2 cannot exceed 128 characters.
Operator

Comparison operator. Insert a space before and after the operator.

Operator Description
= Equal to
<> Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Example

Your data source includes a field to mark the last record of each postal code, and the data source is sorted so that all records with the same postal code appear together. When your data source is set up this way, you can use SET and IF fields in Word to check whether a record is the last occurrence of a postal code in the data source.

With this checking in place, you can use the NEXTIF field to determine whether the current record is the last occurrence of a particular postal code. As long as the current record is not the last occurrence, records for that postal code are added to the current merge document. When the current record is the last occurrence of the postal code, a new merge document is begun for the next postal code that is listed in the data source.

When you insert the following NEXTIF field into a mail merge main document, the NEXTIF field examines the contents of the LastZipcode field in the current data record. If the LastZipcode field is blank, data from the next record in the data source is merged into the current merge document. If the LastZipcode field is not blank, data from the next record in the data source is merged into a new merge document.

{ NEXTIF { MERGEFIELD LastZipcode } = "" }

Instructions

You can use the NEXTIF field in a document or as part of a mail merge.

showTo use the NEXTIF field in a document

  1. On the Insert tab, in the Text group, click Quick Parts, and then click Field.

    word ribbon image

  2. In the Field names list, select NextIf.
  3. In the Field codes box, type the expressions, operator, true text, and false text, following the syntax shown above.
  4. Click OK.

showTo use the NEXTIF field as part of a mail merge

While you are setting up the mail merge, do the following:

  1. On the Mailings tab, in the Write & Insert Fields group, click Rules, and then click Next Record If.

    word ribbon image

  2. In the Field name list, select the name of a merge field, such as City.
  3. In the Comparison list, select the operator that you want. For example, to single out recipients in a particular city, click Equal to.
  4. In the Compare to box, type the value that you want to use. For example, to single out recipients in Tokyo, type Tokyo.

    Note If you selected is blank or is not blank in the Comparison list, leave the Compare to box empty.