Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Time Loop

Posted on 2008-10-01
6
Medium Priority
?
332 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 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

916 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