Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Sep 2002
    Location
    Camp Lejeune, North Carolina
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Elapsed Time (Access 2k)

    I need to be able to click a "start button" and have a timer start, and then click a "stop button" which will stop the timer and display the total time in a text box inbetween the two clicks...is that possible and if it is, will someone help me out? <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Elapsed Time (Access 2k)

    You could use the Windows API GetTickCount function to measure the elapsed time between two events. This function returns a Long that represents the number of milliseconds elapsed since the current Windows session started. It is more accurate than the VBA TImer function. You have to declare an API function in the Declarations section of a code module, as shown in this example:
    <pre>Option Compare Database
    Option Explicit

    Public Declare Function apiGetTickCount Lib "kernel32" _
    Alias "GetTickCount" () As Long</pre>

    <pre>Public Sub TimeSub()

    Dim lngStartTime As Long
    Dim lngStopTime As Long
    Dim dblElapsedTime As Double
    Dim strMsg As String
    Dim n As Integer

    lngStartTime = apiGetTickCount()

    For n = 1 To 1000
    Debug.Print n + n
    Next n

    lngStopTime = apiGetTickCount()
    dblElapsedTime = (lngStopTime - lngStartTime) / 1000

    strMsg = "Elapsed Time: " & dblElapsedTime & " seconds."
    MsgBox strMsg, vbInformation, "ELAPSED TIME"

    End Sub</pre>

    You should be able to adapt this to whatever it is you are trying to time by setting start time when you click "Start" button and setting stop time when you click "Stop" button, then calculating the elapsed time as illustrated.

    HTH

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Elapsed Time (Access 2k)

    How precise to you need to be? Create 2 date variables in the declarations section of your form, call them StartTime and EndTime. Create an unbound textbox called txtElapsedTime In the Click Event of the first button, put in StartTime = Now(). In the ClickEvent of the 2nd button, put in EndTime=Now() and also txtElapsedTime = Format(EndTime-StartTime,"ttttt").
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •