Microsoft Access VBA Programming for the Absolute Beginner

Searches for the first record that meets designated criteria.

Syntax

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.

Example

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

Comments

Категории