Results 1 to 8 of 8

Thread: Timer Intervals

  1. #1
    Join Date
    Mar 2004
    Posts
    287

    Unanswered: Timer Intervals

    Is there anyway to have two seperate Timer Intervals on a form

    and also only have it running it only run on one database even if two are open at the same time.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    For two timer events, try something like:
    Code:
    Sub Form_Load()
        Me.TimerInterval = 1000
    End Sub
    
    Sub Form_Timer()
     
     MsgBox Me.TimerInterval
     If Me.TimerInterval = 1000 Then
     'Insert code
      Me.TimerInterval = 500
     Else
     'Insert code
      Me.TimerInterval = 1000
     End If
    End Sub
    Please ask questions if you don't understand any of the code
    EDIT: Just to point out this is completely untested!
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    why would you want two separate timer intervals, can you not make one timer interval a number of counts of the other (eg if you want a second timer and a minute timer then timer2 is effectively when timer1 as cycled 60 times)

    timers are not cheap, they can be resource and processor hungry, so unless you really really need one then Id suggest dont use 'em.

    occasionally you do need a timer, but remember to run the timer at say 5x..10x's the required granularity if you need to rely on the accuracy of the interval. you cannot rely on timers in the VBA environment to work as relaible clocks... the message event may get through when you want, it may not.

    if you merely want to kick off some process at a specific time then consider using something like windows scheduler.

    out of curiosity what requirement makes you need 2 timers?
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Mar 2004
    Posts
    287
    i have a subform that i need to refresh every 15 seconds, but i also have to input some inbox data (exchange link) every 5 minutes

    also, is there an easy way to have a check so that if more than one instances are running it only runs the refresh/updates / timer once for the first user (or once for all users i mean)

  5. #5
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    In order to keep this to updating for only the first user, you will have to go to a shared table where you can put a data and time the function (update) started. Then before ever doing this timer function, check the shared table value. If it has been started for today, ignore it. If not started yet today, start it, update the value in the table and continue.

    For the 15 second timer, just set your timer interval for 15 seconds, then use as counter and every time you get to 20 or greater than 20, reset the counter, and then do the item you want to do every 5 minutes. I say to check for >= 20 just because I'm paranod. What if, somehow it got past the 20? Does that mean I never want to check it again? No, anything 20 and greater should cause the 5 minute reset, and operation.
    HTH,

  6. #6
    Join Date
    Mar 2004
    Posts
    287
    Thanks. I think the best way for me to do this is to use one timer and use some sort of flag for the running of the timer.

    that way if it has run then timerflag = 0 and it doesn't re-run until the timer resets timerflag=1

  7. #7
    Join Date
    Mar 2004
    Posts
    287
    i think i have solved this using the following code;

    Code:
    Private Sub Form_Load()
    
    Me.TimerInterval = 150000
    Code:
    Sub Form_Timer()
    
    If Me.TimerInterval = 150000 Then
        ' MY CODE GOES HERE FOR TIMER EVENT
        Me.TimerInterval = 150001
        Else
            If Me.TimerInterval = 150001 Then
            DoCmd.CancelEvent
            Me.TimerInterval = 150000
            Else
        End If
    End If
    What do you think guy - good eh?! That means it will only run it every 5 mins and if it has already run then it won't run again!

    [/code]
    Last edited by NeilMansell; 04-16-07 at 12:57.

  8. #8
    Join Date
    Mar 2004
    Posts
    287
    problem sorted - thanks for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •