Use Stopwatch to trigger event

S

Stockwell43

Hello,

I found a Stopwatch database and downloaded it to see how it worked, pretty
cool. Could I click the start button when I open the database to run it and
when it hits certain times have it trigger certain things?

Example:

Once it's running, when it hits 15:00 (15 minutes) run this macro, 02:30:00
(two and a half hours) open this form etc....

There is nothing in the database other than one forma and here is all the
code:

Option Compare Database
Option Explicit

Dim TotalElapsedTime As Long
Dim StartTime As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long


Private Sub cmdTimer_Click()
Me.lblElapsed.Visible = True
If Me.TimerInterval = 0 Then
StartTime = GetTickCount()
Me.TimerInterval = 10
Me!cmdTimer.Caption = "Stop"
Me!cmdReset.Enabled = False
Else
TotalElapsedTime = TotalElapsedTime + (GetTickCount() - StartTime)
Me.TimerInterval = 0
Me!cmdTimer.Caption = "Start"
Me!cmdReset.Enabled = True
End If
End Sub

Private Sub Form_Current()
DoCmd.Restore



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() - StartTime) + TotalElapsedTime

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!lblElapsed.Caption = Hours & ":" & Minutes & ":" & Seconds & ":" &
MilliSec

End Sub

Private Sub cmdReset_Click()
TotalElapsedTime = 0
Me!lblElapsed.Caption = "00:00:00:00"
Me!lblElapsed.Visible = False
End Sub

Where would I put code to trigger my examples if I am able to it?

Thanks!!
 
S

Stockwell43

Hi ErezM,

Pretty cool, works like a charm, thanks!!!

Not to sound dense but how would I do it the other way you are referring to
for future reference?
 
S

Stockwell43

Thank you very much! I will try this out and copy it down in my code book for
future reference. Thank you again and I appreciate your all help!!!

ErezM via AccessMonster.com said:
using the form's properties window
set TimerInterval to 1000 (the code will run every 1 second) or 60000 (the
code will run every 1 Minute)

create a form-wide variable
Private TimeWentBy As Long
(place the above line just under the "option Compare" and "Option Explicit"
statements at the top of the form's code window)

then add an event procedure to the OnTimer event of the form

Private Sub Form_Timer()
TimeWentBy=TimeWentby+1
Select Case TimeWentBy
Case 10
Code to run after 10 minutes or seconds
case 60
Code to run after 1 hour
End Select
End Sub

good luck
Stockwell43 said:
Hi ErezM,

Pretty cool, works like a charm, thanks!!!

Not to sound dense but how would I do it the other way you are referring to
for future reference?
hi
you can add lines just before the EndSub of Form_Timer event you specified
[quoted text clipped - 79 lines]
 

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

Top