Array VBA



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!!!

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
TotalElapsedMilliSec = TotalElapsedMilliSec + (GetTickCount() -
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

Allen Browne

You don't need a timer to calculate how long the record was being edited.
You just need to store the time when the record was dirtied (the Form_Dirty
event), and when it was finally updated (the Form_BeforeUpdate event).

This example records the number of seconds between when the user started
editing the record, and when they finished. Naturally, only the time for
most recent edit of that record is stored.

Dim mdtStartEdit As Date

Private Sub Form_Dirty(Cancel As Integer)
mdtStartEdit = Now()
End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.ElapsedTime = DateDiff("s", mdtStartEdit, Now())
End Sub

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

**VBA Code Help Please!!!** 1
Use Stopwatch to trigger event 2
Windows startup 3
Invoice number 5
hh:mm:ss on a timer 2