MailMergeDataField.AddToRecipientFields Method (Publisher)
Adds the parent MailMergeDataField object from a particular data source to the master data source (collection of data fields) for a mail-merge publication.
expression A variable that represents a MailMergeDataField object.
This method works only if the parent MailMergeDataField object has not already been mapped to a recipient field. You can use the IsMapped property of the MailMergeDataField object to determine if the object has already been mapped.
The following Microsoft Visual Basic for Applications (VBA) macro shows how to use the AddToRecipientFields method to add a data field (column) in a particular data source to the master data source (combined recipient list) for the publication.
Before running this macro, replace datasourceindex with the index number of a valid data source in the data source collection of the active document, and replace fieldname with the name of the field in the data source that you want to add to the combined list of recipient fields.
See the Item method topic for an example of how you can use the Name property of the DataSource object to determine the index number of the data source you want.
Public Sub AddToRecipientFields_Example() Dim pubMailMergeDataSources As Publisher.MailMergeDataSources Dim pubMailMergeDataField As Publisher.MailMergeDataField Set pubMailMergeDataSources = ThisDocument.MailMerge.DataSource.DataSources Set pubMailMergeDataField = pubMailMergeDataSources.Item(datasourceindex).DataFields.Item("fieldname") If pubMailMergeDataField.IsMapped Then Debug.Print "This field is already mapped!" Else pubMailMergeDataField.AddToRecipientFields Debug.Print "Field added successfully. (You can verify this by looking at the recipient or product list in the UI.)" End If End Sub