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?
Automatic shutdown options for Microsoft Access?
Collapse
X
-
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. -
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.
This code relies on the following Function to return the time that the system has been idle.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
I think I included everything needed for this code....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
Hope this hepps!Comment
-
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 FilesComment
Comment