Guus2005
AWF VIP
- Local time
 - Today, 03:06
 
- Joined
 - Jun 26, 2007
 
- Messages
 - 2,642
 
While looking for fast code i found this one sitting in a forgotten directory on my NAS.
It has a different way of addressing a field in a recordset.
I don't know where i got it from but here it is:
tblStatus had 85K records in the sample database.
DoitSlow took 1000msec
DoitFast took 200msec
The sample database is attached.
Share & Enjoy!
	
	
	
		
 It has a different way of addressing a field in a recordset.
I don't know where i got it from but here it is:
tblStatus had 85K records in the sample database.
DoitSlow took 1000msec
DoitFast took 200msec
The sample database is attached.
Share & Enjoy!
		Code:
	
	
	Public Function DoitSlow()
    Dim strStaStatus As Variant
    Dim lngConID     As Long
    Dim lngStaID     As Long
    Dim rst          As DAO.Recordset
    
    Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblStatus", dbOpenDynaset)
    rst.MoveFirst
    Do Until rst.EOF
        strStaStatus = rst("staStatus")
        lngConID = rst("ConID")
        lngStaID = rst("staID")
        rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
End Function
Public Function DoitFast()
    Dim strStaStatus As Variant
    Dim lngConID     As Long
    Dim lngStaID     As Long
    Dim rst          As DAO.Recordset
    Dim fld1         As DAO.Field
    Dim fld2         As DAO.Field
    Dim fld3         As DAO.Field
    
    Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblStatus", dbOpenDynaset)
    Set fld1 = rst("staStatus")
    Set fld2 = rst("ConID")
    Set fld3 = rst("staID")
    
    rst.MoveFirst
    Do Until rst.EOF
        strStaStatus = fld1
        lngConID = fld2
        lngStaID = fld3
        rst.MoveNext
    Loop
    rst.Close
    Set rst = Nothing
End Function