MailMergeDataSource.FindRecord method (Word)
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.
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
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.