PRB: Find Methods Don't Use Indexes to Speed Up VB Data Access

Last reviewed: February 18, 1996
Article ID: Q108380
The information in this article applies to:

- Professional Edition of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

The find methods take longer to find farther records than nearer records. For example, the FindFirst method takes longer to find records that are farther into the Dynaset or Snapshot. Using FindFirst, FindNext, or FindLast on indexed fields isn't any faster than on non-indexed fields.

CAUSE

Creating a Dynaset or Snapshot is relatively fast because of indexes. Indexes are used when you create the Dynaset or Snapshot, such as when you specify a selection criteria or an ORDER BY clause in the CreateDynaset method. However, after the Dynaset or Snapshot is created, it does not use the indexes for searches.

The find and move methods always search sequentially within the current Dynaset or Snapshot. The find and move methods don't use indexes. For example, the FindLast and MoveLast methods require reading the entire recordset before processing continues.

The find methods are: FindFirst, FindLast, FindNext, and FindPrevious. The move methods are: MoveFirst, MoveLast, MoveNext, and MovePrevious.

WORKAROUND

Repositioning the record pointer to a location far into a large Dynaset or Snapshot may be faster if you re-create the Dynaset or Snapshot instead of searching the existing one.

For example, you could change the RecordSource property of a data control at run time as follows:

   txtSearchString = "target string to find"
   ' Place the following two lines on one, single line:
   data1.Recordsource = "select * from mytable where myfield = '" &
      txtSearchString & "' order by myotherfield"
   data1.Refresh   ' Update the data control with the new Recordset

You can also open a Table object in addition to the Dynaset or Snapshot. You can use the Seek method on the Table to find a specific record keyed by an index.

STATUS

This behavior is by design.

REFERENCES

  • "Microsoft Visual Basic 3.0: Professional Features Book 2: Data Access Guide," Chapter 3. See the section "Positioning the Current Record in a Recordset."
  • Help menu in Visual Basic.


Additional reference words: 3.00
KBCategory: kbprg kbprb
KBSubcategory: APrgDataOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 18, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.