ActiveX Timer control use

  • Thread starter Thread starter Stewart
  • Start date Start date
S

Stewart

I need more than one timer on a form, so I'm trying to learn how to use
the ActiveX Timer control in an Access 2002 form. Here's a snip of my
test code:

Private Sub cmdTest_Click()
Dim bEndTimer4 As Boolean
Forms!frmMain!Timer4.Interval = 4000 'Approx 2 Seconds
bEndTimer4 = False
Forms!frmMain!Timer4.Enabled = True
Do
DoEvents
Sleep 5
Loop Until bEndTimer4 = True
'Forms!frmMain!Timer4.Enabled = False
If bEndTimer4 = True Then
MsgBox "Timer Timed and Period Ended"
Else
MsgBox "Timer Did not time"
End If
End Sub
 
hi Stewart,
I need more than one timer on a form, so I'm trying to learn how to use
the ActiveX Timer control in an Access 2002 form.
Why do you need more timers? This is not usual. Can you give us a short
description of what you like to achieve?


mfG
--> stefan <--
 
Stefan said:
hi Stewart,


Why do you need more timers? This is not usual. Can you give us a short
description of what you like to achieve?


mfG
--> stefan <--

It may not be usual to you, but I've often seen 2-3 timers in one form.

I have a form timer running to time I/O card port reads. The second
timer I need is for a periodic serial port send & ack receive.
 
hi Stewart,
It may not be usual to you, but I've often seen 2-3 timers in one form.
I have a form timer running to time I/O card port reads. The second
timer I need is for a periodic serial port send & ack receive.
You only need one timer firing at the least common denominator of your
frequencies.


mfG
--> stefan <--
 
In addition to the absolutely correct advice Stefan gave you, it's the
form's TimerInterval property you need to set, and it's in milliseconds. In
other words,

Me.TimerInterval = 4000

will be 4 seconds, not 2 seconds.
 
Douglas said:
In addition to the absolutely correct advice Stefan gave you, it's the
form's TimerInterval property you need to set, and it's in milliseconds. In
other words,

Me.TimerInterval = 4000

will be 4 seconds, not 2 seconds.

Ok

I had changed the interval value, but not the comment, which souldn't
effect the operation. So am I to understand that I Can Not use the
ActiveX timer in VBA? I can't understand how I can have a single form
timer running for one function, and also use it for another feature
while its timing the first.
 
Stewart said:
Ok

I had changed the interval value, but not the comment, which souldn't
effect the operation. So am I to understand that I Can Not use the
ActiveX timer in VBA? I can't understand how I can have a single form
timer running for one function, and also use it for another feature while
its timing the first.

You don't need an ActiveX timer.

Let's say you've got one event that you want to happen every minute, and
another one every 20 seconds.

Set the form's TimerInterval to 20000 (twenty seconds).

Have code like the following in the form's Timer event:

Private Sub Form_Timer
Static intOccurrences As Integer

intOccurrences = intOccurences + 1

' Do the event that's supposed to happen every 20 seconds

If intOccurrences = 3 Then
' Do the event that's supposed to happen every minute
intOccurrences = 0
End If

End Sub
 
Back
Top