How to Use Seek and MoveNext to Find a Group/Range of RecordsLast reviewed: February 18, 1996Article ID: Q110497 |
The information in this article applies to:
SUMMARYThe Seek method can search for a value only in an indexed field. Seek can find only one record at a time. The Seek method alone cannot find all duplicate field values. After doing a Seek, to find a group of records that have indexed field values that are duplicates or within a given range, you must do a series of move methods (MoveNext or MovePrevious). After each move method in a loop, you must check the indexed field value until your criteria is exceeded. The indexed field values are automatically in alphabetical or numerical order. The sample program below uses a Seek method, then uses MoveNext in a loop to roughly emulate the FindNext method. NOTE: FindNext applies only to Dynasets or Snapshots. The Seek method applies only to Table object variables.
MORE INFORMATIONThe Seek method is very fast, but doesn't support SQL or wildcard searches to find groups of articles. Seek is mainly useful for finding one, single record that matches or exceeds a given value. You can use one of the following methods instead of the Seek method to find a group of records:
Seek can use only the following comparison operators: >, >=, <=, <, =, and <>. 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. Thus, if three or more records have duplicate values in the current index, the Seek method cannot locate the middle records. Seek can locate only the first or last of those records, depending upon the comparison operator used. A move method is required to locate those middle records. A MoveNext always moves forward one record from the current record found by a Seek, independent of the comparison operator that Seek used. MovePrevious moves one record previous.
Example: How to Use Seek and MoveNext to Find a Group of RecordsThe following sample program finds all records for which the PubID field is 2 in the BIBLIO.MDB database (9 records). The program uses one Seek to find the first record for which PubID is 2. The NoMatch property is False if the first match is found. From there onwards, the program uses MoveNext and tests MyTable!PubID in a loop to find all remaining records where PubID is 2. You could also modify this program to find a range of PubID field values.
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |