Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically Close Form After Certain Idle Time

I am having a little bit problem on my access form.

I have 2 forms:

  • menu-form
  • input-form

After input-form has been idle for one minute, I want to close it and go back to the menu-form.

This is my code that isn't working.

Public ExpireTime    As Date  'expiration time-date value

Sub ResetExpiration()             

    If ExpireTime <> 0 And ExpireTime > Now Then
        Application.OnTime ExpireTime, "FormExpire", schedule:=False
    End If

    ExpireTime = Now + 1 / 1440#    

    Application.OnTime ExpireTime, "FormExpire", schedule:=True

End Sub

I also created a macro with this in it.

Sub FormExpire()
   Unload input-form
End Sub
like image 414
jake Avatar asked Nov 11 '22 07:11

jake


1 Answers

You need to set the form.Timer to 60000 (that is 1 minute) then use on OnTimer event to check if some properties have changed. Below I quickly wrote something to give you an idea, but it is not complete nor tested.

Option Compare Database
Option Explicit

Dim isIdle As Boolean


Private Sub Form_LostFocus()
    'you can use this event also
End Sub


Private Sub Form_Timer()
    Dim ctlName As String, wasDirty As Boolean
    If ctlName = vbNullString Then ctlName = Me.ActiveControl.Name
    If Me.ActiveControl <> ctlName Then isIdle = False
    If wasDirty <> Me.Dirty Then isIdle = False
    'more checks....
    If isIdle Then DoCmd.Close acForm, Me.Name
End Sub
like image 162
iDevlop Avatar answered Nov 15 '22 07:11

iDevlop