Find Method

The Find method on a Recordset object locates or seeks to the next record in a Recordset object that meets a particular condition and makes this the current record. This method can be used to seek to a specific record in a Recordset object based on a where clause (similar to an SQL where clause) defined by the user.

recordset.Find Criteria, SkipRecords, SearchDirection, Start

Parameters

ADO supports four arguments for the Find method, but the last three arguments are optional and have default values as noted following:

Criteria
This BSTR parameter specifies the criteria used for locating or seeking to a record in a Recordset object.
SkipRecords
This optional parameter specifies a Long that indicates the number of records to skip (whether to skip the current record) when locating a record in a Recordset object. The default value for this argument is 0 (don't skip the current record). The first time a Find method is used, this argument is usually set to 0 (the default). On subsequent calls to this method to seek other records that meet this condition, this argument would normally be set to 1, to skip one record forward before finding the next record that matches the search Criteria. A negative value for this parameter is not supported by the OLE DB Provider for AS/400 and VSAM.
SearchDirection
This optional parameter is an enumeration that specifies the direction for the search. It can be one of the following enumerated values for SearchDirectionEnum:
Enumeration Value Description
adSearchForward 0 Search forward from the current record.
adSearchBackward 1 Search backward from the current record. This option is not supported by the OLE DB Provider for AS/400 and VSAM.

This optional argument defaults to adSearchForward.

Start
This optional parameter specifies the starting location for a search, which can be a bookmark or an enumeration indicating the current, first, or last record in a Recordset object. This argument is a Variant and can be either a bookmark or one of the following enumerated values for BookmarkEnum:
Enumeration Value Description
adBookmarkCurrent 0 The current record.
adBookmarkFirst 1 The first record.
adBookmarkLast 2 The last record.

This optional argument defaults to adBookmarkCurrent.

Remarks

The first parameter is the only required argument for the Find method. All of the other arguments are optional and have default values. This first argument is a single-condition where clause. The construction of a single-condition where clause consists of a column name (the database field), an operator (greater than or equal, for example), and a literal value.

Examples of acceptable single-condition where clauses are as follows:

Note that variables cannot be used as substitutes for literal values. If the file has multiple keys in the index, using the "=" operator will always fail since the values of all keys cannot be specified.

In order to use the Recordset Find method, an AS/400 logical file or a mainframe KSDS or RRDS file must be used. If this method is used on an AS/400 physical file or any other mainframe file type, then this method fails.

The Start parameter must not be specified on any mainframe file that is marked as supporting bookmarks. If the Start parameter is specified the Find method will return an error. The error string returned is "The application is using a value of the wrong type for the current operation". This results from a limitation with the current implementation of ADO.

If the CursorLocation property is set to adUseClient (use the client cursor engine), the Filter method will work if MDAC 2.0 is installed but will not work properly with earlier versions of ADO.