Solved

VBA Time Loop

Posted on 2008-10-01
6
321 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 85

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 85
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 85
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

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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