nschroeder
nschroeder
- Local time
- Today, 16:31
- Joined
- Jan 8, 2007
- Messages
- 186
My form has a toggle button, tglAutoRefresh, that works with the timer event to to automatically requery the form data every 60 seconds. The code includes a DoCmd.FindRecord to re-select the record they were on. It works perfectly. However, I also want the button to serve as an immediate "refresh" button when it is clicked "on". In that case, it refreshes the data but selects the 1st record instead of the one it was on before. In both cases, I am setting the focus on the control being searched for before I execute the FindRecord, and I added a message box to verify that the variables have the correct values, which they do? Why does it work from the timer, but not from the button. Here's the code. Thanks much for any assistance.
Code:
Private Sub Form_Timer()
FromTimer = True
If tglAutoRefresh.Value Then
Call RefreshRecords
End If
FromTimer = False
End Sub
Private Sub tglAutoRefresh_Click()
If tglAutoRefresh.Value Then
Call RefreshRecords
End If
End Sub
Private Sub RefreshRecords()
Application.Echo (False)
RcdCnt = Me.RecordsetClone.RecordCount
If RcdCnt > 0 Then
If FromTimer Then
CurEANum = Me.EANum
End If
Me.Requery
Me.EANum.SetFocus
MsgBox "Finding " & CurEANum & " in " & Screen.ActiveControl.Name
DoCmd.FindRecord CurEANum, acEntire, True, acSearchAll, True, acCurrent, True
Else
Me.Requery
End If
Application.Echo (True)
End Sub