Visual Basic Tip: 09/18/95

How to speed database field access.

  In VB professional version 3.0, use the Field variable type to

  reference a database field repeatedly (ex: in a loop).  This 

  method can be many times faster than using the fields property.

  The database engine will not have to resolve the field name

  for each iteration through a loop, thus saving time!  See code

  fragment below for an example of this tip.  The critical lines

  have a comment to the right starting with '*.

  Dim mydb As Database

  dim myset As dynaset

  dim afld as field                '* dim the field variable *


  Set mydb = OpenDatabase(defdir$ & "FONTS.MDB", True, False)

  sql$ = "SELECT DISTINCTROW * FROM FontInfo WHERE [Font Family] = 1"

  Set myset = mydb.CreateDynaset(sql$)

  Set afld = myset.Fields("Chars") '* set the field variable *

  if myset.recordcount > 0 then


      i = i    1

      TheChars(i) = afld           '* use instead of myset.Fields("Character") * 


    loop while not myset.eof

  end if



Return to Phil's Web Page

Created by: Philip