AddNextIf Method

Applies To

MailMergeFields collection object.

Description

Adds a NEXTIF field to a mail merge main document. Returns a MailMergeField object. A NEXTIF field compares two expressions, and if the comparison is true, the next data record is merged into the current merge document.

Syntax

expression.AddNextIf(Range, MergeField, Comparison, CompareTo)

expression Required. An expression that returns a MailMergeFields object.

Range Required Range object. The location for the NEXTIF field.

MergeField Required String. The merge field name.

Comparison Required Long. The operator used in the comparison. Can be one of the following WdMailMergeComparison constants: wdMergeIfEqual, wdMergeIfGreaterThan, wdMergeIfGreaterThanOrEqual, wdMergeIfIsBlank, wdMergeIfIsNotBlank, wdMergeIfLessThan, wdMergeIfLessThanOrEqual, or wdMergeIfNotEqual.

CompareTo Required String. The text to compare with the contents of MergeField.

See Also

AddNext method, AddSkipIf method.

Example

This example adds a NEXTIF field before the first MERGEFIELD field in Main.doc. If the next postal code equals 98004, the next data record is merged into the current merge document.

Documents("Main.doc").MailMerge.Fields(1).Select
Selection.Collapse Direction:=wdCollapseStart
Documents("Main.doc").MailMerge.Fields.AddNextIf _
    Range:=Selection.Range, MergeField:="PostalCode", _
    Comparison:=wdMergeIfEqual, CompareTo:="98004"