Solved

Access VBA - make timer run on each minute

Posted on 2009-07-12
7
350 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
[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
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

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)

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

733 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