MailMergeFields.AddNextIf Method (Word)

Adds a NEXTIF field to a mail merge main document. Returns a MailMergeField object.


expression. AddNextIf( _Range_ , _MergeField_ , _Comparison_ , _CompareTo_ )

expression Required. A variable that represents a 'MailMergeFields' collection.


Name Required/Optional Data Type Description
Range Required Range object The location for the NEXTIF field.
MergeField Required String The merge field name.
Comparison Required WdMailMergeComparison The operator used in the comparison.
CompareTo Required String The text to compare with the contents of MergeField.

Return Value



A NEXTIF field compares two expressions, and if the comparison is true, the next record is merged into the current merge document.


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

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

See also

MailMergeFields Collection Object