Bespoke Software Development - Reliability, Expertise, Commitment
01695 720562
info@pssuk.com
  Home  |   Bespoke Software  |   Web Applications  |   Database Development  |   About  |   Resources  

Access VBA Programming - Performance

DCount can be Slow

Using DCount in a VBA loop on a table with 1000s of records, with a where condition can be slower than opening a recordset with a query.

    Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset
Set cn = CurrentProject.Connection
Dim rs2 As New ADODB.Recordset
rs.Open "CrewList", cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
Do While Not rs.EOF
' Following method is much faster than using DCount("CrewCertID", "CrewCert", where) 2 times per loop rs2.Open "select * from crewcert where crewID = " & rs!CrewID & " AND certificateID = 105", cn Do While Not rs2.EOF

rs!FRC = 0 If rs2!ValidTo >= Date Then
rs!FRC = 1
ElseIf IsNull(rs2!ValidFrom) And Not IsNull(rs2!ValidTo) Then
rs!FRC = 1
End If
rs2.MoveNext
Loop rs2.Close rs.Update rs.MoveNext
Loop
rs.Close

 

 

 

 

 

 

 

Copyright © 2012 Paul Stanley Software 7 Needham Way, Skelmersdale, Lancashire, WN8 6PR 01695 720562 info@pssuk.com
UK Bespoke Software Development; Custom database & Web Business Applications; Software Developer; Lancashire, North West
Manchester, Liverpool, Warrington, St Helens, Southport, Preston, Blackburn, Bolton, Blackpool, Lancaster, Skelmersdale, Runcorn