Automatic shutdown options for Microsoft Access?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JY799
    New Member
    • Jan 2020
    • 1

    Automatic shutdown options for Microsoft Access?

    I build & share multiple Access databases with co-workers who sometimes leave them open overnight, preventing me from performing some functions. How can I set up an automatic shutdown of these databases so I can work on them when others have left them open?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32668

    #2
    Options are to have a Form that stays open all the time with a timer process that checks the time and closes the database depending on your required conditions, or, get the administrators of the domain to set restricted logging on hours for those that need to be logged off - but not for you obviously.

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3665

      #3
      Here is a sample of what NeoPa is talking about (having stolen most of this code from him in the past....). This will close the DB after 60 minutes.

      Code:
      Option Compare Database
      Option Explicit
      
      Private Sub Form_Timer()
      On Error GoTo EH
      
          If Now() >= DateAdd(Interval:="n", _
                              Number:=60, _
                              Date:=IdleSince()) Then _
              Call DoCmd.Quit
          
          Exit Sub
      EH:
          MsgBox "There was an error you big dummy!" & _
              vbCrLf & vbCrLf & _
              Err.Number & ":" & Err.Description
          Exit Sub
      End Sub
      This code relies on the following Function to return the time that the system has been idle.

      Code:
      Public Function _
          IdleSince( _
              Optional ByVal fSet As Boolean = False) _
          As Date
          Static strPrevState As String
          Static dtPrevious   As Date
          Dim strState        As String
          Dim objVar          As Object
      
      On Error Resume Next
      
          With Screen
              strState = _
                  strState & "," & _
                  .ActiveDatasheet.Name & "," & _
                  .ActiveDatasheet.SelTop & "," & _
                  .ActiveDatasheet.SelLeft & "," & _
                  .ActiveForm.Name & "," & _
                  .ActiveReport.Name & "," & _
                  .ActiveControl.Name & "," & _
                  .ActiveControl.Text
          End With
      
      On Error GoTo 0
      
          strState = _
              strState & _
              ";Forms"
          For Each objVar In Forms
              strState = _
                  strState & _
                  "," & _
                  objVar.Name
          Next objVar
      
          strState = _
              strState & _
              ";Reports"
          For Each objVar In Reports
              strState = _
                  strState & _
                  "," & _
                  objVar.Name
          Next objVar
      
          'If we pop up a new form to notify the
          'user then strState will change even
          'without human intervention
          'so we allow for this with fSet.
      
          If strState <> strPrevState Then
              strPrevState = strState
              If Not fSet Then _
                  dtPrevious = Now()
          End If
      
          IdleSince = dtPrevious
      
      End Function
      I think I included everything needed for this code....

      Hope this hepps!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Here is a Demo that will detect Idle & Total Idle System Time and after a predetermined period (1 minute for this Demo) Exit/Quit the DB. You can modify the value of the IDLEMINUTES Constant in the Form's Timer() Event to any Value to Quit after X minutes of inactivity. Currently, the Value of IDLEMINUTES is:
        Code:
        Const IDLEMINUTES = 1
        Attached Files

        Comment

        Working...