MailMergeDataSource.FindRecord Method

Word Developer Reference

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.

Syntax

expression.FindRecord(FindText, Field)

expression   Required. A variable that represents a MailMergeDataSource object.

Parameters

Name Required/Optional Data Type Description
FindText Required String The text to be looked for.
Field Required Variant The name of the field to be searched.

Return Value
Boolean

Remarks

This method corresponds to the Find Record button on the Mail Merge toolbar.

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 record in which the FirstName field contains "Joe." If the record is found, the number of the record is stored in the numRecord variable.

Visual Basic for Applications
  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

See Also