Timed Check Box ?

N

niuginikiwi

I have a YES/NO field called LogOff in a table called tblLogoff. The default
value is NO.
And I have a form called frmLogoff bound to tblLogoff. I have a checkbox
with recourd source as Logoff.

What I want to that form to do is check the check the PC time say every 3
minutes and when the time is 12pm, it ticks the check box and when the time
is 12.30pm then it will uncheck the checkbox.

I think this can be done but I just don't know how to come up with the vba
code to put behind the form to carry out this actions.

Here is a psudocode:
'I will put say value 15000 on the Timer Interval property of the form.

If time() = 12.00pm then
me.chkLogoff = true
ElseIf time()=12:30pm then
me.checkLogoff = false
End If


Thanks in advance for any help.
 
K

Klatuu

As written, you timer event will fire every 15 seconds. The timer interval
propery is in milliseconds, so 1000 = 1 second. To get 3 minutes, it would
be 60 * 3 * 1000 or 180000, but I would use one minute or 60000 or you could
miss it and be late turning it on or off.

And the code in the timer event could be:

Me.LogOff = IsBetween(Format(Now,"hh:mm"), "00:00", "00:29")

Here is the IsBetween function. Paste it into a standard module and you can
use it anywhere in your application. Being the lazy type, I wrote it so I
did not have to repeatedly rewrite it for every use.


Public Function IsBetween(varCheckVal As Variant, varLowVal As Variant,
varHighVal As Variant) As Boolean
On Error GoTo IsBetween_Error

IsBetween = varCheckVal >= varLowVal And varCheckVal <= varHighVal


IsBetween_Exit:

Exit Function
On Error GoTo 0

IsBetween_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure IsBetween of Module modUtilities"
GoTo IsBetween_Exit
End Function
 
N

niuginikiwi

Hi Dave,

I have changed the timer interval value to 1 minute (60000) and created a
standard module and stuck your isBetween code plus set the Timer event of the
form to Me.LogOff = IsBetween(Format(Now,"hh:mm"), "00:00", "00:29")
But that doesn't seem to be changing the status of my Check Box.

I checked again to make sure I didn't miss anything.

Is there something else we are missing here?
 
K

Klatuu

Is your check box named LogOff?
If not, change LogOff to the name of the check box.
 

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