|  | Use Stopwatch to trigger event |  | |
| | | Stockwell43 |  |
| Posted: Wed Sep 03, 2008 2:10 pm Post subject: Use Stopwatch to trigger event |  |
| |  | |
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!! |
| |
| | | ErezM via AccessMonster.c |  |
| Posted: Wed Sep 03, 2008 2:51 pm Post subject: Re: Use Stopwatch to trigger event |  |
| |  | |
hi you can add lines just before the EndSub of Form_Timer event you specified use something like If Hours=1 then Docmd.OpenForm "Form1Hour" if Minutes=15 then DoCmd.OpenForm "Form15Minutes" and so on....
but if we're at it, you can use the form's timer alone, without the API calls and all the rest of the code, just set the timerinterval to whatever you want and a static variable that increments every time Form_Timer is triggered
good luck
Stockwell43 wrote:
| Quote: | 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!!
|
-- May all beings be happy.
Message posted via AccessMonster.com LINK |
| |
| | | Stockwell43 |  |
| Posted: Wed Sep 03, 2008 3:02 pm Post subject: Re: Use Stopwatch to trigger event |  |
| |  | |
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?
"ErezM via AccessMonster.com" wrote:
| Quote: | hi you can add lines just before the EndSub of Form_Timer event you specified use something like If Hours=1 then Docmd.OpenForm "Form1Hour" if Minutes=15 then DoCmd.OpenForm "Form15Minutes" and so on....
but if we're at it, you can use the form's timer alone, without the API calls and all the rest of the code, just set the timerinterval to whatever you want and a static variable that increments every time Form_Timer is triggered
good luck
Stockwell43 wrote: 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!!
-- May all beings be happy.
Message posted via AccessMonster.com LINK
|
|
| |
| | | ErezM via AccessMonster.c |  |
| Posted: Wed Sep 03, 2008 4:04 pm Post subject: Re: Use Stopwatch to trigger event |  |
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 wrote:
| Quote: | 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]
Thanks!!
|
-- May all beings be happy.
Message posted via AccessMonster.com LINK |
| |
| | | Stockwell43 |  |
| Posted: Wed Sep 03, 2008 5:51 pm Post subject: Re: Use Stopwatch to trigger event |  |
| |  | |
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" wrote:
| Quote: | 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 wrote: 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]
Thanks!!
-- May all beings be happy.
Message posted via AccessMonster.com LINK
|
|
| |
|
|