MailMergeFields.AddNextIf method (Word)
Adds a NEXTIF field to a mail merge main document. Returns a MailMergeField object.
Syntax
expression. AddNextIf
( _Range_
, _MergeField_
, _Comparison_
, _CompareTo_
)
expression Required. A variable that represents a 'MailMergeFields' collection.
Parameters
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
MailMergeField
Remarks
A NEXTIF field compares two expressions, and if the comparison is true, the next record is merged into the current merge document.
Example
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.
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"
See also
MailMergeFields Collection Object
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.