Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect If Refresh routine is running by Timer & prevent a user restart

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
Hi All,

I have form that has a refresh command button. This form runs the same refresh routine every 5 minutes using the
form's on timer event. I want to include code that

1) Prevents the on timer event from executing the refresh routine if it is already running as a result a user
clicking the "refresh" command button.

2)Informs the user if the interval since the last time it ran is less than 60 seconds give the user a choice to cancel or continue.

3)Enables the "Refresh" command button to reset the Timer Inteval after running the refresh routine.

Any help would be very appreciated.

Thanks!!!
 
dmon000,
Sounds like the easiest solution would be to use a flag to keep track of the last time the Refresh occured:

Code:
'The following is a global declaration
Private mdteLastRefresh As Date

Private Sub Form_Activate()
  mdteLastRefresh = Now
End Sub

Private Sub Form_Timer()
  Form_Refresh True
End Sub

Private Sub Command2_Click()
  Form_Refresh False
End Sub

Private Sub Form_Refresh(OnTimer As Boolean)
  Const strcMsg As String = "It's been less than 60 seconds. Continue with refresh?"
  Dim blnRefresh As Boolean
  Dim lngSeconds As Long
  lngSeconds = DateDiff("s", mdteLastRefresh, Now)
  If OnTimer Then
    Me.Command2.Enabled = False
  Else
    Me.TimerInterval = 0
  End If
  DoCmd.Hourglass True
  DoEvents
  Select Case lngSeconds
    Case Is < 10
      blnRefresh = False
    Case Is < 60
      If OnTimer Then
        blnRefresh = False
      Else
        blnRefresh = MsgBox(strcMsg, vbYesNo, "Confirm Refresh") - 7
      End If
    Case Else
      blnRefresh = True
    End Select
    
    If blnRefresh Then
      Debug.Print "Form Requeried"
      Me.Requery
      mdteLastRefresh = Now
    End If
    
    DoCmd.Hourglass False
    If OnTimer Then
      Me.Command2.Enabled = True
    Else
      Me.TimerInterval = 300000
    End If
End Sub

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top