Class MailMergeDataField (Word VBA)

The class 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). To use a MailMergeDataField class variable it first needs to be instantiated, for example


Dim mmd as MailMergeDataField
Set mmd = ActiveDocument.MailMerge.DataSource.DataFields(Index:=1)

For Each

Here is an example of processing the MailMergeDataField items in a collection.


Dim mmdDataField As MailMergeDataField
For Each mmdDataField In ActiveDocument.MailMerge.DataSource.DataFields
	
Next mmdDataField

Index

Returns a Long that represents the position of an item in a collection.


Dim lngIndex As Long
lngIndex = ActiveDocument.MailMerge.DataSource.DataFields(1).Index

Name

Returns name of the specified object.


Dim strName As String
strName = ActiveDocument.MailMerge.DataSource.DataFields(1).Name

Value

Returns the contents of the mail merge data field or mapped data field for the current record.

Use the ActiveRecord property to set the active record in a mail merge data source.


For Each dataF In _ 
 Documents("Main.doc").MailMerge.DataSource.DataFields 
 If dataF.Value <> "" Then dRecord = dRecord & _ 
 dataF.Value & vbCr 
Next dataF 
MsgBox dRecord