ADO » Recordset » Seek

Syntax:
recordsetobject.Seek  KeyValues, SeekOption
KeyValues
The KeyValues parameter is a variant array that contains one or more values to compare against the values in each corresponding column.
SeekOption
The SeekOption parameter is one of the SeekEnum constants that specify how to conduct the search. The default is adSeekFirstEQ.

Uses the index of a Recordset to locate a specified row.

The Seek method uses the provider to search using indexes to find a Record in a Recordset that matches the values specified in the KeyValues parameter. If a match occurs, the current record pointer will point to the matching record or where specified by the SeekOption parameter. If no match occurs, the current record pointer will be placed at the end of the Recordset.

Very few providers support this method. The provider must support this method and the use of indexes on the Recordset (see the Index property). This method can only be used with server-side cursors.

There are two mandatory parameters.

PositionEnum Constants
 

Constant Value Description
adSeekAfter 8 Find a key just after the match to KeyValues
adSeekAfterEQ 4 Find a key equal to KeyValues or just after the match
adSeekBefore 32 Find a key just before the match to KeyValues
adSeekBeforeEQ 16 Find a key equal to KeyValues or just before the match
adSeekFirstEQ 1 Find the first key equal to KeyValues
adSeekLastEQ 2 Find the last key equal to KeyValues

Examples

Code:
strIndex = "BigCats"
...
If objRecordset.Supports(adSeek) = True Then
   objRecordset.Index = strIndex
   objRecordset.Seek "Jaguar", adSeekLastEQ
End If
If objRecordset.EOF Then
   MsgBox "Record Not Found", vbOK
End If

See Also: