Stop Watch Issues in Access 2010

Posted on 2012-08-17
Last Modified: 2012-08-19
I have created a stop watch for two fields in a subform on my Data Objects Main form.  I was able to get the stop watch to start and stop and reset; however, the bug I have is that when I click on the Start button it will toggle to Stop. The time starts with 412:44:44:44 and will continue to add the time.  I cannot to get it to start with 00:00:00:00 each time I start it.  It will continue from the 412:44:44:44 even if you click on my reset button it won't truly reset it.  I am very frustrated.  My boss wants to be able to have the time copied and pasted into the field for the time in my subform on the form.
Question by:lauriecking0623
    LVL 13

    Expert Comment

    Can you post an example? You're using a timer control?  I'm guessing it's resetting to Today() or Now() and then getting formatted incorrectly...but that's just a total guess.

    Author Comment

    This is what I used from Microsoft:

    Open any database.
    Create a blank form not based on any table or query and set the following properties for the form:
       ScrollBars: Neither
       RecordSelectors: No
       NavigationButtons: No
       OnTimer: [Event Procedure]
       TimerInterval: 0
    Add a text box to the form and set the following properties for the text box:
       Name: ElapsedTime
       DefaultValue: "00:00:00:00"
       Enabled: No
       Locked: Yes
    Add a command button to the form and set the following properties for the command button:
       Name: btnStartStop
       Caption: Start
       OnClick: [Event Procedure]
    Add a second command button to the form and set the following properties for the second command button:
       Name: btnReset
       Caption: Reset
       OnClick: [Event Procedure]
    Click Code on the View menu to open the editor. Type the following lines in the Declarations section:
    Option Explicit
    Dim TotalElapsedMilliSec As Long
    Dim StartTickCount As Long
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Set the OnTimer property of the form to the following event procedure:
    Private Sub Form_Timer ()

       Dim Hours As String
       Dim Minutes As String
       Dim Seconds As String
       Dim MilliSec As String
       Dim Msg As String
       Dim ElapsedMilliSec As Long

       ElapsedMilliSec = (GetTickCount() - StartTickCount) + _

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

       Me!ElapsedTime = Hours & ":" & Minutes & ":" & Seconds & ":" _
          & MilliSec

    End Sub
    Set the OnClick property of the btnStartStop command button to the following event procedure:
    Private Sub btnStartStop_Click()

       If Me.TimerInterval = 0 Then
          StartTickCount = GetTickCount()
          Me.TimerInterval = 15
          Me!btnStartStop.Caption = "Stop"
          Me!btnReset.Enabled = False
          TotalElapsedMilliSec = TotalElapsedMilliSec + _
             (GetTickCount() - StartTickCount)
          Me.TimerInterval = 0
          Me!btnStartStop.Caption = "Start"
          Me!btnReset.Enabled = True
       End If

    End Sub

    Set the OnClick property of the btnReset command button to the following event procedure:
    Private Sub btnReset_Click()
       TotalElapsedMilliSec = 0
       Me!ElapsedTime = "00:00:00:00"
    End Sub
    Open the form in Form view to test the stop watch.
    LVL 29

    Expert Comment

    The code from Microsoft works fine.  All these controls and code are in the subform and not in the main form, right?  If you're still having problems, perhaps you can upload a copy of your database with just this form.
    LVL 29

    Accepted Solution

    Here's a database with the code as you've described above.  Maybe you could see where yours is different.

    Author Comment


    This is perfect. Now, if I could copy the value to a specific field, I would be thrilled. I am going to see if I can create a copy button that would allow me to pick the field to copy the information into. I will look at my code again. Thank you so much.

    Author Closing Comment

    I was able to get my stop watch timer to work on my form. This was perfect!

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now