The information in this article applies to:
SUMMARYThis article compares the Seek method to the find methods (FindFirst, FindLast, FindNext, and FindPrevious) for data access in Visual Basic. MORE INFORMATION
The Seek and find methods differ in performance and in the type of
recordsets to which they apply:
FindFirst, FindLast, FindNext, FindPrevious MethodsThe FindFirst, FindLast, FindNext, and FindPrevious methods locate the first, last, next, or previous record, respectively, that satisfies the specified criteria and makes that record the current record. These methods are referred to as the find methods and have the following syntax:
If the recordset contains more than one record that matches the criteria, FindFirst locates the first occurrence, FindNext locates the next occurrence, and so on. You can follow a find method with a move method, such as MoveNext, which moves to the next record regardless of whether it matches any criteria. If no matching records are found, the NoMatch property is True and the current record remains the same as it was before the find method was used. NOTE: With a data control, if an Edit or AddNew operation is pending when you use one of the find or move methods, the Update method is automatically invoked if not intercepted during the Validate event. CAUTION: In the Professional Edition of Visual Basic, if you are not using a data control and use one of the find or move methods while an Edit or AddNew method is pending, any existing changes will be lost and no error will occur. An Edit or AddNew will be pending until an Update occurs. For more information, see the Update method in the Help menu. Example Code for FindFirst MethodThe following example creates a Dynaset, and then uses FindFirst to locate the first record satisfying the title condition:
Seek MethodThe Seek method locates a record that meets the specified criteria for the current index in an indexed table and makes it the current record. The Seek method has the following syntax:
To use the Seek method, you must first use the OpenTable method to create an object variable for the table. Seek searches through the specified Table using the current index and locates the first record satisfying the criteria specified by comparison and the key values (key1, key2...) and makes it the current record. You must set the current index with the Index property before you use Seek. If the index identifies a non-unique-key field, Seek locates the first record satisfying the criteria. When the comparison is =, >=, >, or <>, Seek starts at the beginning of the index and searches forward. When the comparison is <= or <, Seek starts at the end of the index and searches backward. If <table> doesn't refer to an open table, or if there is no current index, an error occurs. Always inspect the value of the NoMatch property of the recordset to determine whether each Seek method has succeeded. If Seek fails, NoMatch is True and the current record is unchanged. Example Code for Seek MethodThe following example uses Seek to locate the first record in the Publishers table where the PubID field is 3, using the existing primary key index:
REFERENCES
For more information, please read the Visual Basic online Help for the
Seek, FindFirst, FindLast, FindNext, and FindPrevious Methods.
Additional query words: 3.00 MoveFirst MoveLast MoveNext MovePrevious
Keywords : |
Last Reviewed: June 23, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |