Share via


MailMergeDataField Object

Word Developer Reference

Represents a single mail merge field in a data source. The MailMergeDataField object is a member of the MailMergeDataFields collection. The MailMergeDataFields collection includes all the data fields in a mail merge data source (for example, Name, Address, and City).

Remarks

Use DataFields(Index), where Index is the data field name or the index number, to return a single MailMergeDataField object. The index number represents the position of the data field in the mail merge data source. The following example retrieves the first value from the FName field in the data source attached to the active document.

Visual Basic for Applications
  first = _
    ActiveDocument.MailMerge.DataSource.DataFields("FName").Value

The following example displays the name of first field in the data source attached to the active document.

Visual Basic for Applications
  MsgBox ActiveDocument.MailMerge.DataSource.DataFields(1).Name

You cannot add fields to the MailMergeDataFields collection. All data fields in a data source are automatically included in the MailMergeDataFields collection.

See Also