Solved

# Access VBA - make timer run on each minute

Posted on 2009-07-12
Medium Priority
372 Views
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
Question by:Murray Brown
[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

LVL 75

Expert Comment

ID: 24837499
60000

mx
0

Author Comment

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

peter57r earned 2000 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

Author Closing Comment

ID: 31602722
thanks
0

LVL 74

Expert Comment

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

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

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

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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.
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
###### Suggested Courses
Course of the Month12 days, 6 hours left to enroll

#### 752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.