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
ADO supports four arguments for the Find method, but the last three arguments are optional and have default values as noted following:
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.
Enumeration | Value | Description |
---|---|---|
adBookmarkCurrent | 0 | The current record. |
adBookmarkFirst | 1 | The first record. |
adBookmarkLast | 2 | The last record. |
This optional argument defaults to adBookmarkCurrent.
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.