Solved

VBA Time Loop

Posted on 2008-10-01
6
306 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now