?
Solved

Stop Watch Issues in Access 2010

Posted on 2012-08-17
6
Medium Priority
?
624 Views
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.
0
Comment
Question by:lauriecking0623
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Ryan
ID: 38305800
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.
0
 

Author Comment

by:lauriecking0623
ID: 38305851
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) + _
      TotalElapsedMilliSec

   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
   Else
      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.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38307265
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Accepted Solution

by:
IrogSinta earned 2000 total points
ID: 38307270
Here's a database with the code as you've described above.  Maybe you could see where yours is different.
Stopwatch.accdb
0
 

Author Comment

by:lauriecking0623
ID: 38308054
@IrogSinta

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.
0
 

Author Closing Comment

by:lauriecking0623
ID: 38310155
I was able to get my stop watch timer to work on my form. This was perfect!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
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…

807 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