By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,500 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

Automatic shutdown options for Microsoft Access?

P: 1
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?
1 Week Ago #1
Share this Question
Share on Google+
3 Replies


NeoPa
Expert Mod 15k+
P: 31,606
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.
6 Days Ago #2

twinnyfo
Expert Mod 2.5K+
P: 3,328
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.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub Form_Timer()
  5. On Error GoTo EH
  6.  
  7.     If Now() >= DateAdd(Interval:="n", _
  8.                         Number:=60, _
  9.                         Date:=IdleSince()) Then _
  10.         Call DoCmd.Quit
  11.  
  12.     Exit Sub
  13. EH:
  14.     MsgBox "There was an error you big dummy!" & _
  15.         vbCrLf & vbCrLf & _
  16.         Err.Number & ":" & Err.Description
  17.     Exit Sub
  18. End Sub
This code relies on the following Function to return the time that the system has been idle.

Expand|Select|Wrap|Line Numbers
  1. Public Function _
  2.     IdleSince( _
  3.         Optional ByVal fSet As Boolean = False) _
  4.     As Date
  5.     Static strPrevState As String
  6.     Static dtPrevious   As Date
  7.     Dim strState        As String
  8.     Dim objVar          As Object
  9.  
  10. On Error Resume Next
  11.  
  12.     With Screen
  13.         strState = _
  14.             strState & "," & _
  15.             .ActiveDatasheet.Name & "," & _
  16.             .ActiveDatasheet.SelTop & "," & _
  17.             .ActiveDatasheet.SelLeft & "," & _
  18.             .ActiveForm.Name & "," & _
  19.             .ActiveReport.Name & "," & _
  20.             .ActiveControl.Name & "," & _
  21.             .ActiveControl.Text
  22.     End With
  23.  
  24. On Error GoTo 0
  25.  
  26.     strState = _
  27.         strState & _
  28.         ";Forms"
  29.     For Each objVar In Forms
  30.         strState = _
  31.             strState & _
  32.             "," & _
  33.             objVar.Name
  34.     Next objVar
  35.  
  36.     strState = _
  37.         strState & _
  38.         ";Reports"
  39.     For Each objVar In Reports
  40.         strState = _
  41.             strState & _
  42.             "," & _
  43.             objVar.Name
  44.     Next objVar
  45.  
  46.     'If we pop up a new form to notify the
  47.     'user then strState will change even
  48.     'without human intervention
  49.     'so we allow for this with fSet.
  50.  
  51.     If strState <> strPrevState Then
  52.         strPrevState = strState
  53.         If Not fSet Then _
  54.             dtPrevious = Now()
  55.     End If
  56.  
  57.     IdleSince = dtPrevious
  58.  
  59. End Function
I think I included everything needed for this code....

Hope this hepps!
6 Days Ago #3

ADezii
Expert 5K+
P: 8,669
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:
Expand|Select|Wrap|Line Numbers
  1. Const IDLEMINUTES = 1
Attached Files
File Type: zip Detect System Idle Time.zip (47.9 KB, 2 views)
5 Days Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.