Locates the record in an indexed table-type CdbRecordset object that satisfies the specified criteria for the current index and makes that record the current record (Microsoft Jet workspaces only).
Syntax
VOIDSeek(LPCTSTR pstrComparison,
LONG lNumFields,
COleVariant cKey,
...);
Parameters
Type | Argument | Description |
LPCTSTR | pstrComparison | One of the following string expressions: <, <=, =, >=, or >. |
LONG | lNumFields | The number of key arguments that follow. This argument may have a value from 1 to 13. (The maximum value of this parameter is defined by DAO_MAXSEEKFIELDS.) |
COleVariant | cKey, ... | One or more values corresponding to fields in the CdbRecordset object's current index, as specified by its Index property setting. Seek accepts an unspecified number of arguments, as indicated by the ellipsis symbol ("..."), however you may only have a maximum of 13 key arguments. |
Remarks
You must set the current index with the Index property before you use Seek. If the index identifies a nonunique key field, Seek locates the first record that satisfies the criteria.
The Seek method searches through the specified key fields and locates the first record that satisfies the criteria specified by pstrComparison and cKey. Once found, it makes that record current and sets the NoMatch property to False. If the Seek method fails to locate a match, the NoMatch property is set to True, and the current record is undefined.
If pstrComparison is equal (=), greater than or equal (>=), or greater than (>), Seek starts at the beginning of the index and searches forward.
If pstrComparison is less than (<) or less than or equal (<=), Seek starts at the end of the index and searches backward. However, if there are duplicate index entries at the end of the index, Seek starts at an arbitrary entry among the duplicates and then searches backward.
You must specify values for all fields defined in the index. If you use Seek with a multiple-column index, and you don't specify a comparison value for every field in the index, then you cannot use the equal (=) operator in the comparison. That's because some of the cKey criteria fields will default to Null, which will probably not match. Therefore, the equal operator will work correctly only if you have a record which is all Null except the key you're looking for. It's recommended that you use the greater than or equal (>=) operator instead.
The cKey argument must be of the same field data type as the corresponding field in the current index. For example, if the current index refers to a number field (such as Employee ID), cKey must be numeric.
There doesn't have to be a current record when you use Seek.
You can use the Indexes collection to enumerate the existing indexes.
To locate a record in a dynaset- or snapshot-type CdbRecordset that satisfies a specific condition that is not covered by existing indexes, use the Find methods. To include all records, not just those that satisfy a specific condition, use the Move methods to move from record to record.
You can't use the Seek method on a linked table because you can't open linked tables as table-type Recordset objects. However, if you use the OpenDatabase method to directly open an installable ISAM (non-ODBC) database, you can use Seek on tables in that database.
In an ODBCDirect workspace, the Find and Seek methods are not available on any type of CdbRecordset object, because executing a Find or Seek through an ODBC connection is not very efficient over the network. Instead, you should design the query (that is, using the pstrSource argument to the OpenRecordset method) with an appropriate WHERE clause that restricts the returned records to only those that meet the criteria you would otherwise use in a Find or Seek.
Usage
#include <afxole.h>
#include <dbdao.h>
CdbDBEngine dben;
CdbDatabase dbs;
CdbRecordset rst;
...
// Open a table-type recordset.
rst = dbs.OpenRecordset(..., dbOpenTable);
// Define current index as the LastName index.
rst.SetIndex(_T("LastName"));
// Seek first record with last name equal to Smith
rst.Seek("=", 1, _T("Smith"));