Run code then repeat every 15 minutes

K

Karren Lorr

Hello

I am sorry to re-post this question but I can't get it to work after many
hours of trying and searching various websites for assistance.

I am trying to look to see if a text box on my form contains the string
"Found". If it does it will send an e mail (this section works fine). If it
does not then wait for 15 minutes and repeat the check to look for the string.

I can not get the code to wait and repeat.

I tried John Vinson's code
Me.Timer = 1000*60*15
Call Timer ' to have it "do something" the first time

but in this case I get the error "Method or Data Member not found" with the
Me.Time highlighted.

This is what I'm trying to accomplish (the e mail details have taken out for
this post)

Private Sub Form_Button_Click()
If Me.Found = "Found" Then
Call FnSafeSendEmail("emailaddress", "mailtitle", "mailbody", "", "", "")
DoCmd.Quit
Else
'wait 10 minutes and repeat, this is the section I need help with'
End If
End Sub

This small section of code is the last step in a quite complex set of codes.
All the rest of the process works fine and produces the desired results. It
is just this last section I am having problems with, repeating of the form’s
search of this text box.

Can anyone help with this please
 
P

Peter Hibbs

Karren,

Try this :-

Open the form's property sheet and click on the On Timer event and
then click the ... button (select Code in the pop-up form, if
necessary). In this event add the code below so that it looks
something like this :-

Private Sub Form_Timer()

If Me.Found = "Found" Then
Call FnSafeSendEmail("emailaddress", "mailtitle", "mailbody",
"", "", "")
DoCmd.Quit

End Sub

The Call command should all be on one line, of course.

In your button event you should add this :-

Private Sub Form_Button_Click()
Me.TimerInterval = 900000 '900,000 = 15 mins
End Sub

Note that the first test in the Timer event will not happen until 15
minutes has elapsed, if you want to check the Found field immediately
on clicking the button you can add the code in the Timer event to the
button event. Also, the form should be active all the time the timer
is running, if the form is closed then the timer will stop
(obviously). You could hide it, of course, if you don't need to see it
on screen.

If you need to stop the timer you can reset the TimerInterval property
to 0 but as the database shuts down when the test is True and the
timer expires, I guess you probably don't need this.

HTH

Peter Hibbs.
 
J

John W. Vinson

I tried John Vinson's code
Me.Timer = 1000*60*15
Call Timer ' to have it "do something" the first time

but in this case I get the error "Method or Data Member not found" with the
Me.Time highlighted.

My apologies: as Peter correctly says, it should have been Me.TimerInterval.
 
P

Peter Hibbs

Karren,

One amendment to my previous post, I forgot to insert the End If
command after the DoCmd.Quit statement (but I expect you realised
that).

One other peculiarity I noticed when I tested the code, I initially
used the line that John Vinson used to load the TimerInterval
property, i.e. Me.TimerInterval = 1000 * 60 * 15 but this threw up an
Overflow error at run time which is why I calculated the actual number
of milliseconds and used that. Does anyone know why this is? I am
using A2003 and the code compiles with no problems.

Peter Hibbs.
 

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