Microsoft KB Archive/128813

= ACC2: How to Create a Stopwatch Form =

Article ID: 128813

Article Last Modified on 7/5/2002

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition

-



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:

 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   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   Add a command button to the form and set the following properties for the command button:

     Name: StartStop Caption: Start OnClick: [Event Procedure]   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 </li>  Add a second command button to the form and set the following properties for the second command button:

<pre class="fixed_text">     Name: Reset Caption: Reset OnClick: [Event Procedure] </li>  Enter the following code for the second command button's OnClick property event procedure:

Sub Reset_Click ElapsedMS = 0 Me!ElapsedTime = "" End Sub </li>  Add a text box to the form and set the following properties for the text box:

<pre class="fixed_text">     Name: ElapsedTime Enabled: No     Locked: Yes </li>  Click Code on the View menu to display the form module. In the Declarations section, replace the default statement

<pre class="fixed_text">     Option Compare Database

with the statements:

<pre class="fixed_text">     Option Explicit Dim ElapsedMS </li></ol>

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 ACC: How to Create a Stopwatch Form (95/97)

Keywords: kbhowto kbusage KB128813

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.