FindRecord Method

Microsoft Word Visual Basic

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

Note  Corresponds to the Find Record button on the Mail Merge toolbar.

expression.FindRecord(FindText, Field)

expression    Required. An expression that returns a MailMergeDataSource object.

FindText    Required String. The text to be looked for.

Field    Required Variant. The name of the field to be searched.

Remarks

The FindRecord method does a forward search only. Therefore, if the active record is not the first record in the data source and the record for which you are searching is before the active record, the FindRecord method will return no results. To ensure that the entire data source is searched, set the ActiveRecord property to wdFirstRecord.

Example

This example displays a merge document for the first data record in which the FirstName field contains "Joe." If the data record is found, the number of the record is stored in the numRecord variable.

Dim dsMain As MailMergeDataSource
Dim numRecord As Integer

ActiveDocument.MailMerge.ViewMailMergeFieldCodes = False
Set dsMain = ActiveDocument.MailMerge.DataSource
If dsMain.FindRecord(FindText:="Joe", _
        Field:="FirstName") = True Then
    numRecord = dsMain.ActiveRecord
End If