Help and Support
 

powered byLive Search

ACC2: How to Create a Stopwatch Form

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:128813
Last Review:July 5, 2002
Revision:1.0
This article was previously published under Q128813
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

This article describes how to create and use a form that contains a Start/Stop and a Reset command button that use the form's Timer event to display elapsed hours, minutes, and seconds in a text box control.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

The following example demonstrates how to create and use a form to track elapsed time:
1.Open any database.
2.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
						
3.Type the following code for the form's OnTimer property event procedure:
      Sub Form_Timer ()
         Dim Hours, Minutes, Seconds, MS
         Dim Msg As String

         ElapsedMS = ElapsedMS + Me.TimerInterval

         Hours = Format((ElapsedMS \ 360000), "00")
         Minutes = Format(((ElapsedMS \ 6000) Mod 60), "00")
         Seconds = Format((ElapsedMS \ 100) Mod 60, "00")
         MS = Format((ElapsedMS) Mod 100, "00")

         If Hours > 0 Then Msg = Hours & ":"
         Msg = Msg & Minutes & ":" & Seconds & ":" & MS

         Me!ElapsedTime = Msg
      End Sub
						
4.Add a command button to the form and set the following properties for the command button:
      Name: StartStop
      Caption: Start
      OnClick: [Event Procedure]
						
5.Enter the following code for the command button's OnClick property event procedure:
      Sub StartStop_Click ()
         If Me.TimerInterval = 0 Then
            Me.TimerInterval = 1
            Me![StartStop].Caption = "Stop"
         Else
            Me.TimerInterval = 0
            Me![StartStop].Caption = "Start"
         End If
      End Sub
						
6.Add a second command button to the form and set the following properties for the second command button:
      Name: Reset
      Caption: Reset
      OnClick: [Event Procedure]
						
7.Enter the following code for the second command button's OnClick property event procedure:
       Sub Reset_Click ()
         ElapsedMS = 0
         Me!ElapsedTime = ""
       End Sub
						
8.Add a text box to the form and set the following properties for the text box:
      Name: ElapsedTime
      Enabled: No
      Locked: Yes
						
9.Click Code on the View menu to display the form module. In the Declarations section, replace the default statement
      Option Compare Database
						

with the statements:
      Option Explicit
      Dim ElapsedMS
						
NOTE: The performance of the Stopwatch form will be dependent upon the computer's processor speed. The form may not display actual elapsed time and may vary form computer to computer.

For more information about creating a Stopwatch Form in Microsoft Access 7.0 and 97, please see the following article in the Microsoft Knowledge Base:

142871 (http://support.microsoft.com/kb/142871/EN-US/) ACC: How to Create a Stopwatch Form (95/97)

APPLIES TO
Microsoft Access 2.0 Standard Edition

Back to the top

Keywords: 
kbhowto kbusage KB128813

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.