Trigger events based on time of day....????

J

James W

Hi All.

I am able to trigger forms opening, macros running etc. based on a "Timer"
function. No Problem.

However,


My users frequently close down the application (Access 2000 running on
Windows 2000) which means a timer reset each time rendering the "Timer"
method essentially useless.

What I want to know is... Can I trigger events based on the system time? For
example:

Dim myTime
myTime = Time

If myTime = ("09:00:00 AM") Then
DoCmd. Openform "frmMyForm"
EndIf
?????????

nb. The above code does not work.

I want to run queries and open forms at various times of the day.

Please help. I need to solve this one.


T.I.A.
 
A

Allen Browne

Use the Timer event of the form to periodically test the value of Now().

Logically, though, your code will need to record the fact that each of these
things have already happened today. The Timer event may not trigger at the
exact time, so you can test whether the time has been reached, and whether
the action has already been taken.
 
J

James W

Logically, though, your code will need to record the fact that each of these
things have already happened today. The Timer event may not trigger at the
exact time, so you can test whether the time has been reached, and whether
the action has already been taken.

Ok so I would do something like:


Private Sub Form_Timer()
If Now() = ("09:00:00 AM") Then
DoCmd.OpenForm "MyForm"
EndIf

And somehow count how many times this event had occurred?

If this is correct how would you recommend maintaining the count?
 
A

Allen Browne

It would be:
If TimeValue(Now()) = #9:00:00# Then
DoCmd.OpenForm "MyForm"
EndIf

But of course if the person does not start the database until after 9, or if
the computer is busy at 9 and so the code runs at 9:00:01, then ...
 
J

James W

Hmmmmmmmm

I just tried your suggestion with the following code with the code behind a
simple test form which would then open another form but it didn't work.

Private Sub TimeTest()
If TimeValue(Now()) = #8:50:00 PM# Then
DoCmd.OpenForm "frmSuccess"

End If

End Sub
 
J

James W

Actually Allen, my apologies.

I was able to get it to work in a test context where the evaluation takes
place once.

Now the challenge is to get it to work numerous times across the day.

Thanks for your help.
 
R

Rick Brandt

James W said:
Actually Allen, my apologies.

I was able to get it to work in a test context where the evaluation takes
place once.

Now the challenge is to get it to work numerous times across the day.

Are you using the Timer event? That event automatically fires every n
milliseconds as long as a form is open (you get to set the value of n).
 

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