MailMergeDataField Object

Microsoft Word Visual Basic

MailMergeDataField Object

         
Documents (Document) MailMerge
MailMergeDataSource
MailMergeDataFields (MailMergeDataField)

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).

Using the MailMergeDataField Object

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.

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.

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.