Solved

Access VBA - make timer run on each minute

Posted on 2009-07-12
7
347 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2016 - Blank, Null, or empty string? 9 31
VBA Access 2016 syntax 6 41
Access Open Report with SQL Parameter 11 30
Binding recordsets to a form 6 23
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…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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