Timer Event (1 Viewer)

Jonny45wakey

Member
Local time
Today, 03:03
Joined
May 4, 2020
Messages
48
Hi I would like the on-timer event of a hidden form to trigger

DoCmd.OpenForm "formnamehere"

every hour using the computer time, essentially if time (minutes) = 00 then run the docmd

How would this be formatted in VBA please?

Thanks

Jonny
 
All

I have sorted this through trial and error, on the hidden form is a textbox "txttime" with bounds to =Now()
and timer interval set to 60 seconds.

When the On Timer event fires the following code opens the second form (which is like a popup form)

Private Sub Form_Timer()
Me.Refresh
If Minute(Me.txtTime) = 0 Then
DoCmd.OpenForm "frmReminder"
End If
End Sub


Regards

Jonny
 
What is the point of opening a form this way? Unless you have code that runs when the form opens, the form just sits there looking pretty until the next time the timer runs. And reopening an open form won't change what it displays if it is bound.
 
Just got back from my morning walk, so Pat beat me to it.

With programming (as with much else in life), everything has a purpose. If you pop open a form every hour, there is a question of purpose. You see, forms are generally "action" elements - you DO something with a form. So what is the purpose of opening this form at a specific time? What is your user supposed to do with it? Suppose that the user has to take a rest-room break... Is the form going to stay open until the user comes back? What if the user goes to lunch and happens to be gone 1 hour and 2 minutes - which means the form would open twice? Have you considered contingencies for a user who just minimizes the form because s/he is busy doing something else?

That might have seemed a bit rambling, but that's actually the point. If we have no idea of the context, we cannot give you good advice for what you want to do. We will ramble all over the place trying to decide how to help you do something that might actually be simple but might also turn into a project that is at the level of a Master's Thesis in computer science. So where is this going?

By the way, the more efficient way to do that timer is when it fires and you want to re-trigger it at a specific time, build a time-string to the time you want, then use a DateDiff( "s", Now(), <projected time> ) * 1000 to set the next timer interval.
 
I also forgot to mention that when you use timers, you need to be careful when you are testing. I always add code to my applications that checks the sign in and if it is "me", I ask if the timer should be on, and if no, I turn off all timers. That way I won't clobber myself. If you happen to have a form open that has a live timer event and you are testing some other process and make code changes, you could lose your changes due to the timer. You will get no warning, the code change will simply disappear. So, to be safe, when it is YOU, you only want the timers to be running if it is the timer that you are testing. So the code turns them off or back on as necessary.
 

Users who are viewing this thread

Back
Top Bottom