Access uses an internal Timer fucntion to calculate times....this function returns a Single number that is the number of seconds that have elapsed since midnight. The following problems can occur:
- turns over at midnight, in other words the number starts over
- it turns over after 24 hours, if your calculation is longer than 24 hours the results will be wrong
- not accurate, measures only 1/18-second accuracy
The below code and its usage is much more efficient. Reasons:
- it turns over every 49 days or so
- has no concept of days, so it does not turn over each day
- accurate to 1/1000-second and does not use the floating math of the Timer function
So if you really want to get exact...
Create a new class module called StopWatch
Put the following code in the StopWatch class module:
'*********** Start Code ****************
Private mlngStart As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Sub StartTimer()
mlngStart = GetTickCount
End Sub
Public Function EndTimer() As Long
EndTimer = (GetTickCount - mlngStart)
End Function
' *********** End Code ****************
You use the code as follows:
' *********** Start Code **************
Dim sw as StopWatch
Set sw = New StopWatch
sw.StartTimer
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.