MailMergeFields.AddIf Method

Word Developer Reference

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

Syntax

expression.AddIf(Range, MergeField, Comparison, CompareTo, TrueAutoText, TrueText, FalseAutoText, FalseText)

expression   Required. A variable that represents a MailMergeFields collection.

Parameters

Name Required/Optional Data Type Description
Range Required Range object The location for the IF field.
MergeField Required String The merge field name.
Comparison Required WdMailMergeComparison The operator used in the comparison.
CompareTo Optional Variant The text to compare with the contents of MergeField.
TrueAutoText Optional Variant The AutoText entry that's inserted if the comparison is true. If this argument is specified, TrueText is ignored.
TrueText Optional Variant The text that's inserted if the comparison is true.
FalseAutoText Optional Variant The AutoText entry that's inserted if the comparison is false. If this argument is specified, FalseText is ignored.
FalseText Optional Variant The text that's inserted if the comparison is false.

Return Value
MailMergeField

Remarks

When updated, an IF field compares a field in a record with a specified value, and then it inserts the appropriate text according to the result of the comparison.

Example

This example inserts "for your personal use" if the Company merge field is blank and "for your business" if the Company merge field is not blank.

Visual Basic for Applications
  ActiveDocument.MailMerge.Fields.AddIf Range:=Selection.Range, _
    MergeField:="Company", Comparison:=wdMergeIfIsBlank, _
    TrueText:="for your personal use", _
    FalseText:="for your business"

See Also