Form Timer - Calling a function

gsrajan

Registered User.
Local time
Today, 06:43
Joined
Apr 22, 2014
Messages
227
I wish to automate a function (Function Name: Daily_Activities_Snapshot) - everyday at 5.00 PM. Please let me know whether I can use the form timer event for this. If yes, please let me have an example. If not, please let me know how to do this.

Thanks for your help.
 
You can, but personally I'd create a standalone version of the db that ran this function on startup then quit, and run that db from Windows Scheduled Tasks.
 
Thanks for your reply. Please let me know how to do this - not from standalone DB, but from the linked DB itself. I do not want to close the database after calling this function.

thanks for your help.
 
Not the way I'd go, but try having the timer run once an hour and test:

If Hour(Now()) = 17 Then
 
Thank you,

I tried. Doesn't work. Can you please let me know how you would do. Sorry for the trouble.
 
What exactly did you try? How did it not work?

Like I said, I'd use a stand-alone db and run it from Scheduled Tasks.
 
This is what I tried:

Private Sub Form_Timer()
If Hour(Now()) = 12 Then
Call Daily_Activities_Snapshot
End If
End Sub

But when I call this function from a command button, it works well.
 
What is the timer interval (did it ever run)? Is the form open?
 
Yes the form is open. The time interval is everyday at 5 PM.
 
The timer interval I'm looking for is a property of the form. 5pm would not be a valid entry there.
 
Did it run the code? You realize that will run every 10 seconds? Your function will run 6x per minute times 60 minutes. That's why mentioned an interval that would only run once per hour.
 
No, it did not run the code. I am not sure why.

Thanks again.
 
once an hour could cause this to run at the end of the hour you wish it to.
launching the form at 8:59 will trigger the function to run at 5:59. I think lol.
 
Thank you, it runs the code, if this code is to run only once a day, what should be the time interval.

Thank you,
 
1000 = 1 second
1000 * 60 * 60 * 24

Take my warning though, if you want it to be more accurately triggered around 5PM You'll have to reconsider having it every 5-10-15-20 mins depending on how close to 5PM you want and writing the code to only trigger once in that day.
 
Can you post the db here?

Regarding "once an hour could cause this to run at the end of the hour you wish it to.
launching the form at 8:59 will trigger the function to run at 5:59.
"

That is certainly true, so if the desire is to run at 5, rather than once a day in that hour, the interval would need to be more frequent, the test more complicated, and a method used to prevent it from running more than once. You also have to account for multiple users if applicable. All reasons I'd go the other way. ;)
 

Users who are viewing this thread

Back
Top Bottom