| ACC: Speeding Up Iterative Processes in Visual or Access BasicID: Q112724 
 | 
To 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.
The following is a code example that does not iterate efficiently:
   Sub Slow()
      Dim d As Database
      Dim r As Recordset
      Set d = CurrentDB()
      Set r = d.OpenRecordset("Order Details")
      While Not r.EOF
         r.Edit
         r.Fields("Price") = r.Fields("Qty") * r.Fields("UnitCost")
         r.Update
         r.MoveNext
      Wend
      r.Close
   End Sub 
   Sub Faster()
      Dim d As Database
      Dim r As Recordset
      Dim Price As Field, Qty As Field, UnitCost As Field
      Set d = CurrentDB()
      Set r = d.OpenRecordset("Order Detail")
      Set Price = r.Fields("Price")
      Set Qty = r.Fields("Qty")
      Set UnitCost = r.Fields("UnitCost")
      While Not r.EOF
         r.Edit
         Price = Qty * UnitCost
         r.Update
         r.MoveNext
      Wend
      r.Close
   End Sub For 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 
Version           : WINDOWS:2.0,7.0,97
Platform          : WINDOWS 
Issue type        : kbinfo Last Reviewed: August 2, 1999