VBA Time Loop

Hello,
I'm looking to create a loop that repeats every 5 minutes then I can start the program in the morning
and it will keep running till 6pm.

What would be great if I could start the loop at 9am myself and it will loop every 5 minutes but then
stop everything 9 hours after I originally started it.

Sounds tough
ShockUKAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You can use the Timer event of a Form to do this ...

Sub Form_Timer()

If Hour(Now) > 9 and Hour(Now) < 18 Then
  '/ run your code
End If

End Sub

Set your form's TimerINterval to 300000 (that's 5 minutes X 60 seconds X 1000, which will give you Milliseconds).
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
That should probably be:

If Hour(Now) > 8 and Hour(Now) < 18 Then
0
 
peter57rCommented:
I assume you are talking about an application that will run unattended once you have started it up (not one that a user will be using during the same period)

In that case you could use a startup form or any form that you are happy to open via a menu and use it's Timer event procedure and Timer Interval property to run the code you want.

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ShockUKAuthor Commented:
I was hoping not to use a form at all.
I was planning on getting windows scehduler to start the module and then just leave it running.

Is there a way of doing it without using a form?
0
 
ShockUKAuthor Commented:
Maybe if there is a wait function I could create a work around?
0
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
No, there's no Wait function. The only timer really available is via a Form.

You could build a Loop that would do this, but you would have to somehow call this loop ... you could use an autoexec macro to do this, but why make this more difficult?              
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.