MS Access 2010 Form_Timer 事件仅触发一次
MS Access 2010 Form_Timer event firing only once
与表单关联的计时器存在一些触发问题,谁能告诉我为什么这不起作用,而且只触发一次。
这是代码:
Option Compare Database
Option Explicit
Private Sub CheckingToggle_Click()
If Me.CheckingToggle.value = False Then
Me.TimerInterval = 0
Text35.value = 0
Else
Me.TimerInterval = 5000
Text35.value = 5000
End If
End Sub
Private Sub Form_Load()
CheckingToggle.value = False
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
If CheckingToggle = True Then
Dim rs As DAO.Recordset
'The sql here is operating on the Access Jet tables dont get confused if trying to Mysql functions will not work!!!!
Set rs = CurrentDb.OpenRecordset("SELECT * FROM DataMonitor WHERE IsActive=true " _
& " And ( " _
& " DateAdd('n', [FrequencyMins], [LastCheck]) < #" & Now() & "#" _
& " OR IsNull([LastCheck]))")
'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
'Do our stuff here
DoEvents
Loop
Else
MsgBox "There are no records that are Active which have not been ckecked in the last minute"
End If
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
End If
End Sub
点击切换到 'checked' 后,计时器第一次触发,Form_Timer() 第一行的 break-point 捕获执行,并观察显示时间间隔已正确设置为 5000,但是,无论是否打开和关闭切换,它都不会再次触发,直到表单首次返回设计模式。
虽然从 break-point 继续后,但似乎有些奇怪的是,如果我在没有先停止 运行 代码的情况下将表单切换到设计模式,header说是运行,我被屏蔽了! "you can switch to a different view at this time" ...就好像定时器是 运行 只是事件没有触发。至少 break-point 没有捕捉到它。
我尝试在子程序中放置一个计数器,只是为了测试进程是否 passing-through 而不会以某种方式触发断点,但这并没有增加。这是到目前为止代码的完整性,在尝试调试期间已设置和取消设置定时器间隔 属性,但行为不受影响。
感谢任何帮助。
应该已经意识到 - 答案很明显 - 并不是事件根本没有触发!但是 rs.MoveNext 还没有被包含在循环中,所以它永远不会退出能够再次 运行 定时器事件中的代码!!!
与表单关联的计时器存在一些触发问题,谁能告诉我为什么这不起作用,而且只触发一次。 这是代码:
Option Compare Database
Option Explicit
Private Sub CheckingToggle_Click()
If Me.CheckingToggle.value = False Then
Me.TimerInterval = 0
Text35.value = 0
Else
Me.TimerInterval = 5000
Text35.value = 5000
End If
End Sub
Private Sub Form_Load()
CheckingToggle.value = False
Me.TimerInterval = 0
End Sub
Private Sub Form_Timer()
If CheckingToggle = True Then
Dim rs As DAO.Recordset
'The sql here is operating on the Access Jet tables dont get confused if trying to Mysql functions will not work!!!!
Set rs = CurrentDb.OpenRecordset("SELECT * FROM DataMonitor WHERE IsActive=true " _
& " And ( " _
& " DateAdd('n', [FrequencyMins], [LastCheck]) < #" & Now() & "#" _
& " OR IsNull([LastCheck]))")
'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
'Do our stuff here
DoEvents
Loop
Else
MsgBox "There are no records that are Active which have not been ckecked in the last minute"
End If
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
End If
End Sub
点击切换到 'checked' 后,计时器第一次触发,Form_Timer() 第一行的 break-point 捕获执行,并观察显示时间间隔已正确设置为 5000,但是,无论是否打开和关闭切换,它都不会再次触发,直到表单首次返回设计模式。
虽然从 break-point 继续后,但似乎有些奇怪的是,如果我在没有先停止 运行 代码的情况下将表单切换到设计模式,header说是运行,我被屏蔽了! "you can switch to a different view at this time" ...就好像定时器是 运行 只是事件没有触发。至少 break-point 没有捕捉到它。
我尝试在子程序中放置一个计数器,只是为了测试进程是否 passing-through 而不会以某种方式触发断点,但这并没有增加。这是到目前为止代码的完整性,在尝试调试期间已设置和取消设置定时器间隔 属性,但行为不受影响。
感谢任何帮助。
应该已经意识到 - 答案很明显 - 并不是事件根本没有触发!但是 rs.MoveNext 还没有被包含在循环中,所以它永远不会退出能够再次 运行 定时器事件中的代码!!!