The information in this article applies to:
SUMMARYTo speed up iterative (looping) processes through large numbers of rows in Visual Basic for Applications (or Access Basic in version 2.0), declare all field references explicitly. MORE INFORMATIONThe following is a code example that does not iterate efficiently:
In the example above, the field variable "lookup" (that is, where the
Visual Basic function equates variable names with database fields) for the
three field variables Price, Qty, and UnitCost is performed in the same
While loop in which the calculations are performed. In this configuration,
both calculations and lookups must be performed inside the While loop,
which is not an efficient design.
The following code example is more efficient:
This example runs faster because Visual Basic performs the field lookup
only once for each field and completes it before executing the loop. A
direct reference to each of the three fields is then stored in the three
field variables: Price, Qty, and UnitCost. As a result, no lookup is
required in the While loop, and the field values are accessed and
manipulated directly.
NOTE: The code examples above are for illustrative purposes only. In some cases, an update query can accomplish the task faster, for example, when you need to modify one field based on another field (or fields). Also, speed differences are slight if you are manipulating only a few records. Using the transaction processing features of Visual Basic (BeginTrans, CommitTrans, and Rollback) can also help optimize performance. These features enable Microsoft Access to cache information and reduce disk input and output (I/O). REFERENCESFor more information about transaction processing, search the Help Index for "Transactions," or ask the Microsoft Access 97 Office Assistant. Additional query words: queries programming
Keywords : kbprg kbdta AccCon KbVBA |
Last Reviewed: August 2, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |