Solved

Access VBA - make timer run on each minute

Posted on 2009-07-12
7
343 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

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.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

920 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