ADO Find Method
The Find method is used to search a Recordset for a Record that matches
the search criteria (a search string). This method will work if the
Recordset supports bookmarks. If the search is successful, the current
record pointer will be moved to point to the first Record that matches.
If the search fails, the Recordset will point to either EOF or
BOF.
There is one mandatory and three optional parameters.
You can only search on one field (column).
The comparison operators in Criteria can only be one of the following:
= > >= < <= <> LIKE
You cannot use OR or AND.
The value in Criteria can be a date, number, or string. If the value is
a string, it must be enclosed (delimited) within a pair of single quotes
("Country = ' Germany' ") or a pair of pound signs ("State =
#Bavaria# "). If the value is a date, it must be enclosed (delimited)
within a pair of pound signs ("Birthdate = #11/15/1978# "). Numbers are
not delimited ("Age = 28").
If you are using the LIKE operator, you can also use the asterisk *
wildcard either after the value in Criteria or before and after the
value in Criteria ( "LastName LIKE ' * stein * ' " or "LastName
= ' T * ' ). Some providers also support using the % and _
wildcards.
Syntax
objRecordset.Find(criteria,skiprows,direction,start)
|
Example
varBookMark = rs.Bookmark
rs.MoveFirst
rs.Find "Customers LIKE'* mann'"
If (rs.BOF = True) OR (rs.EOF = True) Then
MsgBox "Record not found"
rs.Bookmark = varBookMark
End If
|
Parameter |
Description |
criteria |
Required. The column name, comparison operator,
and value to use in the search.
Examples:
"Country='Norway'"
"Date>#7/22/97#"
"Country LIKE N*"
Note: This method does not support multi-column
searches (AND or OR) |
skiprows |
Optional. Specifies how many records beyond the
current record to skip before beginning the search. Default is
0 |
direction |
Optional. A SearchDirectionEnum value that
specifies the search direction |
start |
Optional. The starting position for the search |
SearchDirectionEnum Values
Constant |
Value |
Description |
adSearchBackward |
-1 |
Searches backward from the starting position. Stops at the
beginning of the Recordset. If no match, the record pointer is
placed at the beginning of the Recordset |
adSearchForward |
1 |
Searches forward from the starting position. Stops at the
end of the Recordset. If no match, the record pointer is placed
at the end of the Recordset |
|