I created a timer to time certain orders that I will be processing. I
created the timer form based on a table so that the times would be bound (the
ElapsedTime text box) to it. I then added two command buttons, one to reset
the timer, and one to start/stop the timer. I attempted to code it so that
each record would have its own separate timer (before this the timer
continually counted with each record.)The only problem I have is my timer now
counts time very fast and progressively faster as time goes on. I believe
the problem to be in the private sub form timer portion of my code, but have
had no luck. I am a beginning coder and need help desperately!! Here is the
present code. Please Help!!

Option Compare Database
Option Explicit
Dim TotalElapsedSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub cmdReset_Click()
TotalElapsedSec = 0
Me!ElapsedTime = "00:00:00"
End Sub

Private Sub cmdStartStop_Click()

If Me.TimerInterval = 0 Then
StartTickCount = GetTickCount()
Me.TimerInterval = 30
Me!cmdStartStop.Caption = "&STOP"
Me.cmdStartStop.ForeColor = RGB(255, 0, 0)
Me.cmdStartStop.FontSize = "12"
Me!cmdReset.Enabled = False
TotalElapsedSec = TotalElapsedSec + (GetTickCount() - StartTickCount)
Me.TimerInterval = 0
Me!cmdStartStop.Caption = "Start the &Timer"
Me.cmdStartStop.ForeColor = RGB(0, 64, 128)
Me.cmdStartStop.FontSize = "8"
Me!cmdReset.Enabled = True
End If
End Sub

Private Sub Form_Timer()
Dim Hours As String
Dim Minutes As String
Dim Seconds As String
Dim Msg As String
Dim ElapsedSec As Long
Dim hour As Long
Dim minute As Long
Dim second As Long
Dim milisec As Long
Dim temp As String
hour = Left(Me!ElapsedTime, 2)
temp = Left(Me!ElapsedTime, 5)
minute = Right(temp, 2)
second = Right(Me!ElapsedTime, 2)
TotalElapsedSec = 3600000 * hour
TotalElapsedSec = TotalElapsedSec + (60000 * minute)
TotalElapsedSec = TotalElapsedSec + (second * 1000)

ElapsedSec = (GetTickCount() - StartTickCount) + TotalElapsedSec

Hours = Format((ElapsedSec \ 3600000), "00")
Minutes = Format((ElapsedSec \ 60000) Mod 60, "00")
Seconds = Format((ElapsedSec \ 1000) Mod 60, "00")

Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds
End Sub

Rick B

Please do not post your question multiple times. You don't want someone
posting a repose in one group and a separate person working to give you an
answer in another group. It wastes two (or more) peoples' time.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads