Class MailMergeDataSource (Word VBA)

The class MailMergeDataSource represents the mail merge data source in a mail merge operation.

The main procedure of class MailMergeDataSource is Close

Set

To use a MailMergeDataSource class variable it first needs to be instantiated, for example

Dim mmd as MailMergeDataSource
Set mmd = ActiveDocument.MailMerge.DataSource

MailMergeDataSource class variables can be set using the MailMerge.DataSource procedure.

Themes

The following procedures in this class have been grouped together and are described on a separate theme page

Name with its procedures FieldNames, HeaderSourceName, Name and TableName

Methods

This is the main method of the MailMergeDataSource class

Close - Closes the specified Mail Merge data source.

ActiveDocument.MailMerge.DataSource.Close

Other Methods

FindRecord - Searches the contents of the specified mail merge data source for text in a particular field. Returns True if the search text is found.

Dim strFindText As String: strFindText =  
Dim booFindRecord As Boolean
booFindRecord = ActiveDocument.MailMerge.DataSource.FindRecord(FindText:=strFindText)

SetAllErrorFlags - Marks all records in a mail merge data source as containing invalid data in an address field.

Dim strInvalidComment As String: strInvalidComment =  
ActiveDocument.MailMerge.DataSource.SetAllErrorFlags Invalid:=True, InvalidComment:=strInvalidComment

Properties

ActiveRecord returns or sets the active mail merge record. Can be either a valid record number in the query result or one of the WdMailMergeActiveRecord constants.

ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstDataSourceRecord

ConnectString returns the connection string for the specified mail merge data source.

Dim strConnectString As String
strConnectString = ActiveDocument.MailMerge.DataSource.ConnectString

DataFields returns a MailMergeDataFields collection that represents the fields in the specified mail merge data source.

Dim mmdsDataFields As MailMergeDataFields
Set mmdsDataFields = ActiveDocument.MailMerge.DataSource.DataFields

FirstRecord returns or sets the number of the first record to be merged in a mail merge operation.

ActiveDocument.MailMerge.DataSource.FirstRecord =

HeaderSourceType returns a value that indicates the way the header source is being supplied for the mail merge operation.

Dim wmmHeaderSourceType As WdMailMergeDataSource
wmmHeaderSourceType = ActiveDocument.MailMerge.DataSource.HeaderSourceType

Included true if a record is included in a mail merge.

ActiveDocument.MailMerge.DataSource.Included = True

InvalidAddress true for Microsoft Word to mark a record in a mail merge data source if it contains invalid data in an address field.

ActiveDocument.MailMerge.DataSource.InvalidAddress = True

InvalidComments if the InvalidAddress property is True, returns or sets a String that describes an invalid address error.

ActiveDocument.MailMerge.DataSource.InvalidComments =

LastRecord returns or sets the number of the last record to be merged in a mail merge operation.

ActiveDocument.MailMerge.DataSource.LastRecord =

MappedDataFields returns a MappedDataFields collection that represents the mapped data fields available in Microsoft Word.

Dim mdfsMappedDataFields As MappedDataFields
Set mdfsMappedDataFields = ActiveDocument.MailMerge.DataSource.MappedDataFields

Parent returns an object that represents the parent object of the specified MailMergeDataSource object.

Dim objParent As Object
Set objParent = ActiveDocument.MailMerge.DataSource.Parent

QueryString returns or sets the query string (SQL statement) used to retrieve a subset of the data in a mail merge data source.

ActiveDocument.MailMerge.DataSource.QueryString =

RecordCount returns a Long that represents the number of records in the data source.

Dim lngRecordCount As Long
lngRecordCount = ActiveDocument.MailMerge.DataSource.RecordCount

Type returns the type of mail merge data source.

Dim wmmType As WdMailMergeDataSource
wmmType = ActiveDocument.MailMerge.DataSource.Type