Solved

VBA Time Loop

Posted on 2008-10-01
6
311 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:ShockUK
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 22614197
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
 
LVL 84
ID: 22614209
That should probably be:

If Hour(Now) > 8 and Hour(Now) < 18 Then
0
 
LVL 77

Expert Comment

by:peter57r
ID: 22614223
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:ShockUK
ID: 22614256
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
 

Author Comment

by:ShockUK
ID: 22614539
Maybe if there is a wait function I could create a work around?
0
 
LVL 84
ID: 22614779
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

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question