Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA - make timer run on each minute

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 = ???????
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

60000

mx
Avatar of Murray Brown

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks
Pete,
So basically your code checks to see if time is divisible by 5 minutes with no remainder?
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.
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