Timer looping in vba (Access)

点点圈 提交于 2020-01-03 02:45:09

问题


I'm trying to configure a timer to run every 3 minutes in VBA, to loop through my Access database table and validate data. I'm stuck at the point of starting the timer. I wrote this mini script to test the timer:

Function JobNameValidate()
MsgBox ("Hello")
'callAgain.OnTimer
End Function

Function callAgain()
callAgain.TimerInterval = 300000
Forms("HiddenForm1").OnTimer
JobNameValidate
End Function

It loops fine, however it loops instantly, regardless of the TimerInterval put in. I couldn't find any helpful documentation about this online.


回答1:


You can set your form's OnTimer property to a string which starts with = followed by your function name and a pair of parentheses.

The units for TimerInterval are milliseconds. So 3 minutes is 180000 (3 * 60 * 1000).

Function callAgain()
    Forms("HiddenForm1").OnTimer = "=JobNameValidate()"
    Forms("HiddenForm1").TimerInterval = 180000
End Function

I'm not sure why you want to do this with VBA. You could set both those properties in the form's property sheet. But you can do it with VBA if needed.



来源:https://stackoverflow.com/questions/34226998/timer-looping-in-vba-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!