troubleshooting Question

Access 2007 StopWatch on Form

Avatar of JARichard
JARichardFlag for United States of America asked on
Microsoft Access
5 Comments1 Solution2327 ViewsLast Modified:
So this is what I have.  Via Google I found what I needed as far a stopwatch to go onto a form I have for calculating the total time of an event.  I downloaded the db containing this "Stopwatch" form, opened it, and exported that one form to MY db.  Although both Datatbases are 2007 compatible, the form doesnt seem to work the same when put into MY db.  

As a form by itself in my db, it works fine.  I can open the form, press all the buttons and they do exactly as they should.  The stopwatch that I want, however, needs to be embedded into a form I already have.  When I simply copy the elements from the "Stopwatch form" and put them into my already present form, I get errors.  I fixed a few of them, but the main one now appears to be that the timer doesn't actually count, even though as a standalone form it does it just fine.  The coding on the buttons, and the OnTimer event is as follows:

Private Sub btnResetTime_Click()
Dim LngNumOfSecs As Long
Me.TimerInterval = 0
Me![lblTime].Caption = "00:00:00"
LngNumOfSecs = 0
End Sub

Private Sub btnStartTime_Click()
Me.TimerInterval = 1000
End Sub

Private Sub btnStopTime_Click()
Me.TimerInterval = 0
End Sub

Private Sub Form_Timer()
Dim lngNumOfHrs As Long
Dim lngNumOfMins As Long
Dim lngNumOfSecsRem As Long
Dim LngNumOfSecs As Long

LngNumOfSecs = LngNumOfSecs + 1

Select Case LngNumOfSecs
  Case Is > 86400        '>1 day - not equipped for that
  Case Is >= 3600        '>1 hour
    lngNumOfHrs = LngNumOfSecs \ 3600
    lngNumOfMins = ((LngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
    lngNumOfSecsRem = LngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
  Case Is >= 60          '>1 minute
    lngNumOfMins = ((LngNumOfSecs - (lngNumOfHrs * 3600)) \ 60)
    lngNumOfSecsRem = LngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
  Case Is > 0            '< 1 minute
    lngNumOfSecsRem = LngNumOfSecs - ((lngNumOfHrs * 3600) + (lngNumOfMins * 60))
  Case Else              'shouldn't happen, but who knows?
End Select

Me![lblTime].Caption = Format$(lngNumOfHrs, "00") & ":" & Format$(lngNumOfMins, "00") & _
                             ":" & Format$(lngNumOfSecsRem, "00")
End Sub

The timer interval on the form by default is set to 0.

I would really appreciate if someone adept in coding could tell me why this isn't working when placed within a form, but works when in its own form, and how to make it work embedded in my form.  All it does now is when you click [btnStartTime] the [lblTime] displays 00:00:01, and keeps flickering at the currect interval as if it should be counting, but its not changing at all.  The [btnStopTime] works, at least the flickering stops, so that tells me its stoping the cycles even if the time isn't acutally changing.  and [btnResetTime] sets [lblTime] to 00:00:00 as it should.

Thank you in advance for all your assistance.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros