Searches for the first record that meets designated criteria.
DoCmd.FindRecord(FindWhat, Match, MatchCase, Search, SearchAsFormatted, OnlyCurrentField, FindFirst)
with the following parameters:
FindWhat
The Variant containing the data to search for. It can be text, a number, or a date.
Match
A member of the AcFindMatch enumeration that defines where in the field Access looks for the match. Possible values are acAnywhere (the search value can be found anywhere in the field), acEntire (the search value must match the entire field), and acStart (the search value must match the start of the field). The default is acEntire.
MatchCase
A Boolean indicating whether the search is case sensitive (True) or not (False).
Search
A member of the AcSearchDirection enumeration indicating the direction of the search. Possible values are acDown, acSearchAll, and acUp.
SearchAsFormatted
A Boolean that indicates whether to search for data as it’s formatted (True) or as it’s stored in the database (False). The default is False.
OnlyCurrentField
A member of the AcFindField enumeration defining the fields to be searched. Possible values are acAll (all fields of the record) and acCurrent (only the current field). The default is acCurrent.
FindFirst
A Boolean that determines where in the database the search starts. If True, the search starts at the beginning of the database. If False, it starts at the record after the current record.
Private Sub cmdFind_Click() On Error GoTo Err_Hand: Dim strSearchString As String strSearchString = "Street" If Me.cmdFind.Caption = "Find" Then Me.txtAddress.SetFocus DoCmd.FindRecord strSearchString, acAnywhere, False, acDown, , acAll, False Me.cmdFind.Caption = "Find Next" Else If Not Me.Recordset.EOF Then DoCmd.GoToRecord , , acNext If Not Me.Recordset.EOF Then DoCmd.FindNext Else Me.cmdFind.Caption = "Find" DoCmd.GoToRecord , , acFirst End If End If Exit Sub Err_Hand: ' search failed, go to beginning of file DoCmd.GoToRecord , , acFirst End Sub
To search for additional records that match the search criteria, use the FindNext method.
You’re responsible for tracking and handling the record pointer between calls to the FindRecord and FindNext methods.