Array VBA

From: GOL (GOL_at_discussions.microsoft.com)
Date: 01/27/05


Date: Thu, 27 Jan 2005 15:11:02 -0800

I have a timer on a subform on a main "order form." I am timing how long it
takes to process different orders. However, if I change orders in the middle
of timing one, the timer does not reset with next order, just keeps on
running. I believe I need some kind of array code so that the timer is
"bound" in a way to each record (or order). I would like to be able to click
and time different orders at the same time simultaneously--but can only do
one at a time now, and have to reset timer for every order or else it picks
up where last stopped. Here is my current code, which I got from the MS
site. Just in case you don't want to look at the site,the code is below.
Help is GREATLY appreciated. I have worked on this problem for weeks!!!

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q233/2/75.asp&NoWebContent=1

Option Compare Database
Option Explicit

Dim TotalElapsedMilliSec As Long
Dim StartTickCount As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Private Sub cmdStartStop_Click()
    If Me.TimerInterval = 0 Then
        StartTickCount = GetTickCount()
        Me.TimerInterval = 15
        Me!cmdStartStop.Caption = "STOP"
        Me.cmdStartStop.ForeColor = RGB(255, 0, 0)
        Me.cmdStartStop.FontSize = "8"
        Me!cmdReset.Enabled = False
    Else
        TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() -
StartTickCount)
        Me.TimerInterval = 0
        Me!cmdStartStop.Caption = "Start the Timer"
        Me.cmdStartStop.ForeColor = RGB(0, 64, 128)
        Me.cmdStartStop.FontSize = "8"
        Me!cmdReset.Enabled = True
    End If
End Sub

Private Sub cmdClose_Click()
    DoCmd.Close acForm, "frmStopWatch", acSaveNo
End Sub

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

Private Sub cmdReset_Click()
    TotalElapsedMilliSec = 0
    Me!ElapsedTime = "00:00:00:00"
End Sub



Relevant Pages

  • Re: Playing AVI and MPEG using MCI
    ... "mciSendStringA" (ByVal lpstrCommand As String, ... Dim mlRet As Long ... Private Sub CenterObject ... If mlRet 0 Then ...
    (microsoft.public.vb.controls)
  • Change this Program
    ... Private sPathFrom As String ... Private Sub enableControl ... Dim oColor As OLE_COLOR ... Dim sPathTo As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Error when running vb app with FlexGrid control
    ... Private Sub cmdNetChange_Click ... On Error GoTo Command1_Click_Error ... Private Sub fnGetData(strParam0 As String, strParam1 As String, FLX As ... Dim rsADOObject As Recordset ...
    (microsoft.public.vb.general.discussion)
  • Sum in a dynamic query
    ... Private Sub Form_Open ... Dim db As Database, Tbl As TableDef ... Dim db As Database, qd As QueryDef, ctl As Control, s As String, Item As ...
    (comp.databases.ms-access)
  • Re: How to add/load records to combobox ?
    ... Dim rsCustomers As New ADODB.Recordset ... Private msCustomerIDsAs String ... Private Sub Combo1_Click ... Dim sSQL As String ...
    (microsoft.public.vb.controls)