none
Close application RRS feed

  • Question

  • I am trying to write code (VBA) in MS Access to close a database after x amount of time that there were no activity. Say for example a user has opened the database and leaves his desk, the database must close after 10 minutes of being idle.

    I tried using the "On Timer" event, but this event does not do what I want it to do.

    Friday, October 7, 2011 6:49 AM

Answers

  • You can use the Ontime method, but you need to constantly reset the time using other events, indicating that the user is active. So call the sub ResetTimer from any event(s) you choose - but also in the open event of the database so that it is started properly.

    Public NextTime As Date


    Sub ResetTimer()
    On Error Resume Next
    Application.OnTime NextTime, "CloseMe", schedule:=False
    NextTime = Now() + TimeValue("00:10:00")
    Application.OnTime NextTime, "CloseMe"
    End Sub

    Sub CloseMe()
    'Code Here to clean up

    End Sub

     I should note that this is code written and tested in Excel - I think it will work as written in Access, but it may need some modification. 


    HTH, Bernie
    Friday, October 7, 2011 3:00 PM