AddNextIf Method
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.
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 WdMailMergeComparison. The operator used in the comparison.
WdMailMergeComparison can be one of these WdMailMergeComparison constants. |
wdMergeIfEqual |
wdMergeIfGreaterThanOrEqual |
wdMergeIfIsNotBlank |
wdMergeIfLessThanOrEqual |
wdMergeIfGreaterThan |
wdMergeIfIsBlank |
wdMergeIfLessThan |
wdMergeIfNotEqual |
CompareTo Required String. The text to compare with the contents of MergeField.
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"