Solved

Access VBA - make timer run on each minute

Posted on 2009-07-12
7
342 Views
Last Modified: 2012-05-07
Hi

I want my form timer event to run every five minutes on the minute. I achieved this is Visual Studio using
      Me.Timer1.Interval = New TimeSpan(Now.Hour, Now.Minute + 1, 0).Subtract(Now.TimeOfDay).TotalMilliseconds
How would I do the equivalent in Access VBA
Me.TimerInterval = ???????
0
Comment
Question by:murbro
7 Comments
 
LVL 75
ID: 24837499
60000

mx
0
 

Author Comment

by:murbro
ID: 24837676
Hi
Thanks for that but that doresn't answer my question. If I open my database at 08:50:33 (8:50 and 33 seconds) I want it to run next at 08:55:00 and then at 09:00:00
So the first time the timer runs is on the exact minute
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 24837911
This will do what you ask based on whole seconds.
Private Sub Form_Timer()
Static first As Boolean
If first = False Then

    Me.TimerInterval = 1000 * (300 - ((TimeValue(Now()) * 86400) Mod 300))
    first = True
Else
    Me.TimerInterval = 300000
End If
'MsgBox Now()

End Sub

Access does not handle milliseconds natively.
There is a set of functions here that you can utilise to provide milliseconds accuracy.
http://www.devx.com/dbzone/Article/39046/1954

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Closing Comment

by:murbro
ID: 31602722
thanks
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 24839773
Pete,
So basically your code checks to see if time is divisible by 5 minutes with no remainder?
0
 
LVL 77

Expert Comment

by:peter57r
ID: 24839854
Not exactly.
If it's not the first time through the timerinterval is set to 5 minutes.

If it is first time through the timer interval is set to the remaining time until the next 5 minute value.
0
 

Author Comment

by:murbro
ID: 24840249
To clarify...I wanted the timer to run at the beginning of each minute. Because the user can open the app at any point, the first interval is the remainder, eg if the time is 08:02:30 then there are two and a half minutes left to the next 5 minute point. What I did was set the timer to the remainder and then when the timer is run, set the interval to 300000 milliseconds or 5 mins
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

705 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

14 Experts available now in Live!

Get 1:1 Help Now