473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to close out Access when a computer is locked?

I found the vb that explains what to do to detect idle time and close out access automatically when idle and it works great, however this does not work if someone locks their computer but leaves access running.

is there a way to either get this working or to simply force this access database to close, and no other programs or databases, the moment a computer is locked?

the code used to close on idle is merely the microsoft-suggested code (http://support.microsoft.com/kb/128814)
Dec 3 '10 #1

✓ answered by NeoPa

That code was only ever meant for testing. It should work, fundamentally, but it includes a whole bunch of unnecessary lines simply to help me determine what was what.

Here is a sanitised version, with the MsgBox() call where you would want to put the call to Application.Quit (or IdleTimeDetected()) :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' conIdleThreshold determines how much idle time to wait
  5. ' for before running the IdleTimeDetected subroutine.
  6. Private Const conIdleThreshold As Long = 5 * 60& * 1000&
  7.  
  8. Private PrevControlName As String
  9. Private PrevFormName As String
  10. Private ExpiredTime As Long
  11.  
  12. Private Sub Form_Timer()
  13.     Dim ActiveFormName As String
  14.     Dim ActiveControlName As String
  15.  
  16.     On Error Resume Next
  17.  
  18.     ' Get the active form and control name.
  19.     With Screen
  20.         ActiveFormName = .ActiveForm.Name
  21.         If Err = 2475 Then ActiveFormName = "No Active Form"
  22.         ActiveControlName = .ActiveControl.Name
  23.         If Err = 2474 Then ActiveControlName = "No Active Control"
  24.     End With
  25.  
  26.     ' Record the current active names and reset ExpiredTime if:
  27.     '    1. They have not been recorded yet (code is running
  28.     '       for the first time).
  29.     '    2. The previous names are different from the current ones
  30.     '       (the user has done something different during the timer
  31.     '        interval).
  32.     If (PrevControlName = "") _
  33.     Or (PrevFormName = "") _
  34.     Or (ActiveFormName <> PrevFormName) _
  35.     Or (ActiveControlName <> PrevControlName) Then
  36.         PrevControlName = ActiveControlName
  37.         PrevFormName = ActiveFormName
  38.         ExpiredTime = 0
  39.     Else
  40.         ' ...otherwise the user was idle during the time interval, so
  41.         ' increment the total expired time.
  42.         ExpiredTime = ExpiredTime + Me.TimerInterval
  43.     End If
  44.  
  45.     ' Does the total expired time exceed the conIdleThreshold?
  46.     If ExpiredTime >= conIdleThreshold Then
  47.         ' ...if so, then reset the expired time to zero...
  48.         ExpiredTime = 0
  49.         ' ...Clear the timer event...
  50.         Me.TimerInterval = 0
  51.         ' ...and call the IdleTimeDetected subroutine.
  52.         Call MsgBox("Triggered")
  53.     End If
  54. End Sub

16 4913
NeoPa
32,556 Expert Mod 16PB
I can't imagine how it can be possible to detect idle time without working when the keyboard is locked. If the keyboard is locked then the computer is idle.

Maybe if you posted the code we're supposed to be looking at then we may (only may - this should have been available in the question) be able to help.
Dec 5 '10 #2
The microsoft link in the original question suggests adding this code to a form that you force to open upon the start of Access, and further modify that form's properties to remain hidden so that no one closes it out. This is fine but it can be annoying if you are still trying to fine-tune some components of a database that is already seeing occasional use.

If you don't mind being less fancy for a spell, disable the code in your startup switchboard such that it does not close out when a new switchboard or form is opened. You might also need to disable the code that attempts to re-open the main switchboard in your secondary switchboard forms. Then, add this code to your main switchboard instead of a hidden form.

So, if you have work to do and can't risk being interrupted with an untimely close without save, you can just close the main switchboard and not worry about it - well, worry less about it: it is Windows we're talking about...
Dec 6 '10 #3
NeoPa
32,556 Expert Mod 16PB
I used a modified version to test with :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' conIdleThreshold determines how much idle time to wait
  5. ' for before running the IdleTimeDetected subroutine.
  6. Private Const conIdleThreshold As Long = 5 * 60& * 1000&
  7.  
  8. Private PrevControlName As String
  9. Private PrevFormName As String
  10. Private ExpiredTime As Long
  11.  
  12. Private Sub Form_Timer()
  13.     Dim ActiveFormName As String
  14.     Dim ActiveControlName As String
  15.     Dim lngErr As Long, lngIx As Long
  16.  
  17.     On Error Resume Next
  18.     lngErr = 0
  19.  
  20.     ' Get the active form and control name.
  21.     With Screen
  22.         ActiveFormName = .ActiveForm.Name
  23.         If Err = 2475 Then
  24.             ActiveFormName = "No Active Form"
  25.         ElseIf Err Then
  26.             lngErr = Err
  27.         End If
  28.         ActiveControlName = .ActiveControl.Name
  29.         If Err = 2474 Then
  30.             ActiveControlName = "No Active Control"
  31.         ElseIf Err Then
  32.             lngErr = Err
  33.         End If
  34.     End With
  35.     If lngErr Then
  36.         ' ...Clear the timer event...
  37.         Me.TimerInterval = 0
  38.         Call MsgBox(lngErr)
  39.         For lngErr = 1 To 60
  40.             Beep
  41.             For lngIx = 1 To 100
  42.                 DoEvents
  43.             Next lngIx
  44.         Next lngErr
  45.         Stop
  46.     End If
  47.  
  48.     ' Record the current active names and reset ExpiredTime if:
  49.     '    1. They have not been recorded yet (code is running
  50.     '       for the first time).
  51.     '    2. The previous names are different from the current ones
  52.     '       (the user has done something different during the timer
  53.     '        interval).
  54.     If (PrevControlName = "") _
  55.     Or (PrevFormName = "") _
  56.     Or (ActiveFormName <> PrevFormName) _
  57.     Or (ActiveControlName <> PrevControlName) Then
  58.         PrevControlName = ActiveControlName
  59.         PrevFormName = ActiveFormName
  60.         ExpiredTime = 0
  61.     Else
  62.         ' ...otherwise the user was idle during the time interval, so
  63.         ' increment the total expired time.
  64.         ExpiredTime = ExpiredTime + Me.TimerInterval
  65.     End If
  66.  
  67.     ' Does the total expired time exceed the conIdleThreshold?
  68.     If ExpiredTime >= conIdleThreshold Then
  69.         ' ...if so, then reset the expired time to zero...
  70.         ExpiredTime = 0
  71.         ' ...Clear the timer event...
  72.         Me.TimerInterval = 0
  73.         ' ...and call the IdleTimeDetected subroutine.
  74.         Call MsgBox("Triggered")
  75.         For lngErr = 1 To 60
  76.             Beep
  77.             For lngIx = 1 To 100
  78.                 DoEvents
  79.             Next lngIx
  80.         Next lngErr
  81.         Stop
  82.     End If
  83. End Sub
In my testing I found that the code actually did execute. I heard all the beeps then unlocked the screen to find the code at the Stop on line #81.

What causes you to believe the code isn't executing as intended?
Dec 6 '10 #4
i have it set to close after 7 minutes, but when someone leaves their computer locked with this open all day they come back to find it still open.
Dec 6 '10 #5
NeoPa
32,556 Expert Mod 16PB
  1. What does the closing code do (Please post it for me)?
  2. Does it work as expected when the PC is not locked?

In the mean-time, check my version of the code on a test form to see if you come up with the same results as I do.
Dec 6 '10 #6
Expand|Select|Wrap|Line Numbers
  1. Sub IdleTimeDetected(ExpiredMinutes)
  2. Application.Quit acQuitSaveNone
  3. End Sub
that is the idletimedetected subroutine

It does work as expected when the computer is not locked, and I'll give the beep a shot.
Dec 6 '10 #7
NeoPa
32,556 Expert Mod 16PB
The only thing to come to mind is that you don't clear the timer (Me.TimerInterval = 0), so the .Quit may fail (as the database has outstanding code running). It's probably a long-shot, but try it out anyway.
Dec 6 '10 #8
i just pasted your code in with the application.quit instead of the messagebox. so far it seems to be working just fine.

Thanks!
Dec 6 '10 #9
NeoPa
32,556 Expert Mod 16PB
That code was only ever meant for testing. It should work, fundamentally, but it includes a whole bunch of unnecessary lines simply to help me determine what was what.

Here is a sanitised version, with the MsgBox() call where you would want to put the call to Application.Quit (or IdleTimeDetected()) :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' conIdleThreshold determines how much idle time to wait
  5. ' for before running the IdleTimeDetected subroutine.
  6. Private Const conIdleThreshold As Long = 5 * 60& * 1000&
  7.  
  8. Private PrevControlName As String
  9. Private PrevFormName As String
  10. Private ExpiredTime As Long
  11.  
  12. Private Sub Form_Timer()
  13.     Dim ActiveFormName As String
  14.     Dim ActiveControlName As String
  15.  
  16.     On Error Resume Next
  17.  
  18.     ' Get the active form and control name.
  19.     With Screen
  20.         ActiveFormName = .ActiveForm.Name
  21.         If Err = 2475 Then ActiveFormName = "No Active Form"
  22.         ActiveControlName = .ActiveControl.Name
  23.         If Err = 2474 Then ActiveControlName = "No Active Control"
  24.     End With
  25.  
  26.     ' Record the current active names and reset ExpiredTime if:
  27.     '    1. They have not been recorded yet (code is running
  28.     '       for the first time).
  29.     '    2. The previous names are different from the current ones
  30.     '       (the user has done something different during the timer
  31.     '        interval).
  32.     If (PrevControlName = "") _
  33.     Or (PrevFormName = "") _
  34.     Or (ActiveFormName <> PrevFormName) _
  35.     Or (ActiveControlName <> PrevControlName) Then
  36.         PrevControlName = ActiveControlName
  37.         PrevFormName = ActiveFormName
  38.         ExpiredTime = 0
  39.     Else
  40.         ' ...otherwise the user was idle during the time interval, so
  41.         ' increment the total expired time.
  42.         ExpiredTime = ExpiredTime + Me.TimerInterval
  43.     End If
  44.  
  45.     ' Does the total expired time exceed the conIdleThreshold?
  46.     If ExpiredTime >= conIdleThreshold Then
  47.         ' ...if so, then reset the expired time to zero...
  48.         ExpiredTime = 0
  49.         ' ...Clear the timer event...
  50.         Me.TimerInterval = 0
  51.         ' ...and call the IdleTimeDetected subroutine.
  52.         Call MsgBox("Triggered")
  53.     End If
  54. End Sub
Dec 6 '10 #10
hey, i had a follow-up question, and since I don't really understand some of the code you posted, i figured I should just ask directly.

In addition to the activecontrolname and and activeformname I would also like to include the activecontrolvalue: if that changes then also reset the counter.

I think it would go something like this, but I don't know what the question marks (????) would be. I've underlined the parts I added, and bolded/italicized the part for which I haven't a clue. Of course, the bold doesn't show up so well (the question marks should be a dead giveaway)...
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database 
  2. Option Explicit 
  3.  
  4. ' conIdleThreshold determines how much idle time to wait 
  5. ' for before running the IdleTimeDetected subroutine. 
  6. Private Const conIdleThreshold As Long = 5 * 60& * 1000& 
  7.  
  8. Private PrevControlName As String 
  9. Private PrevFormName As String 
  10. Private ExpiredTime As Long 
  11. Private PrevControlValue as string  
  12. Private Sub Form_Timer() 
  13.     Dim ActiveFormName As String 
  14.     Dim ActiveControlName As String 
  15.     Dim ActiveControlValue as String
  16.     On Error Resume Next 
  17.  
  18.     ' Get the active form and control name. 
  19.     With Screen 
  20.         ActiveFormName = .ActiveForm.Name 
  21.         If Err = 2475 Then ActiveFormName = "No Active Form" 
  22.         ActiveControlName = .ActiveControl.Name 
  23.         If Err = 2474 Then ActiveControlName = "No Active Control" 
  24.         ActiveControlValue = .ActiveControl.Value
  25.         If Err = ???? Then ActiveControlValue = "No Value"    
  26. End With 
  27.  
  28.     ' Record the current active names and reset ExpiredTime if: 
  29.     '    1. They have not been recorded yet (code is running 
  30.     '       for the first time). 
  31.     '    2. The previous names are different from the current ones 
  32.     '       (the user has done something different during the timer 
  33.     '        interval). 
  34.     If (PrevControlName = "") _ 
  35.     Or (PrevFormName = "") _ 
  36.     Or (ActiveFormName <> PrevFormName) _ 
  37.     Or (ActiveControlName <> PrevControlName) _
  38.     Or (ActiveControlValue <> PrevControlValue) Then 
  39.         PrevControlName = ActiveControlName 
  40.         PrevFormName = ActiveFormName
  41.         PrevControlValue = ActiveControlValue        
  42.         ExpiredTime = 0 
  43.     Else 
  44.         ' ...otherwise the user was idle during the time interval, so 
  45.         ' increment the total expired time. 
  46.         ExpiredTime = ExpiredTime + Me.TimerInterval 
  47.     End If 
  48.  
  49.     ' Does the total expired time exceed the conIdleThreshold? 
  50.     If ExpiredTime >= conIdleThreshold Then 
  51.         ' ...if so, then reset the expired time to zero... 
  52.         ExpiredTime = 0 
  53.         ' ...Clear the timer event... 
  54.         Me.TimerInterval = 0 
  55.         ' ...and call the IdleTimeDetected subroutine. 
  56.         Call MsgBox("Triggered") 
  57.     End If 
  58. End Sub 
  59.  
Dec 20 '10 #11
This is simple if you have a network admin account. You ether go to or remote into the offending computer. Then log-out the person using the admin account. They'll lose their work but you'll get your DB back.
Dec 21 '10 #12
NeoPa
32,556 Expert Mod 16PB
That's actually quite good thinking. A user may well stay in the same control and still be active. I like that.

You've made a pretty good stab at it I would say, but you probably want to treat the .Value as a Variant type, rather than as a String specifically. I've made some changes to your code, but not highlighted where they are. You'll need to copy and paste the whole lot.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. ' conIdleThreshold determines how much idle time to wait
  5. ' for before running the IdleTimeDetected subroutine.
  6. Private Const conIdleThreshold As Long = 5 * 60& * 1000&
  7.  
  8. Private PrevControlName As String
  9. Private PrevFormName As String
  10. Private ExpiredTime As Long
  11. Private PrevControlValue as Variant
  12.  
  13. Private Sub Form_Timer()
  14.     Dim ActiveFormName As String
  15.     Dim ActiveControlName As String
  16.     Dim ActiveControlValue as Variant
  17.  
  18.     On Error Resume Next
  19.  
  20.     ' Get the active form and control name.
  21.     With Screen
  22.         ActiveFormName = .ActiveForm.Name
  23.         If Err = 2475 Then ActiveFormName = "No Active Form"
  24.         ActiveControlName = .ActiveControl.Name
  25.         If Err = 2474 Then
  26.             ActiveControlName = "No Active Control"
  27.             ActiveControlValue = Null
  28.         Else
  29.             ActiveControlValue = .ActiveControl.Value
  30.         End If
  31.     End With
  32.  
  33.     ' Record the current active names and reset ExpiredTime if:
  34.     '    1. They have not been recorded yet (code is running
  35.     '       for the first time).
  36.     '    2. The previous names are different from the current ones
  37.     '       (the user has done something different during the timer
  38.     '        interval).
  39.     If (PrevControlName = "") _
  40.     Or (PrevFormName = "") _
  41.     Or (IsNull(PrevControlValue)) _
  42.     Or (ActiveFormName <> PrevFormName) _
  43.     Or (ActiveControlName <> PrevControlName) _
  44.     Or (ActiveControlValue <> PrevControlValue) Then
  45.         PrevControlName = ActiveControlName
  46.         PrevFormName = ActiveFormName
  47.         PrevControlValue = ActiveControlValue
  48.         ExpiredTime = 0
  49.     Else
  50.         ' ...otherwise the user was idle during the time interval, so
  51.         ' increment the total expired time.
  52.         ExpiredTime = ExpiredTime + Me.TimerInterval
  53.     End If
  54.  
  55.     ' Does the total expired time exceed the conIdleThreshold?
  56.     If ExpiredTime >= conIdleThreshold Then
  57.         ' ...if so, then reset the expired time to zero...
  58.         ExpiredTime = 0
  59.         ' ...Clear the timer event...
  60.         Me.TimerInterval = 0
  61.         ' ...and call the IdleTimeDetected subroutine.
  62.         Call MsgBox("Triggered")
  63.     End If
  64. End Sub
Dec 21 '10 #13
NeoPa
32,556 Expert Mod 16PB
Endkill Emanon:
This is simple if you have a network admin account. You ether go to or remote into the offending computer. Then log-out the person using the admin account. They'll lose their work but you'll get your DB back.
I'm not sure what you're trying to say exactly, but the question was specifically asking about closing down when the database was idle. Kicking a user off would not fall into that category.
Dec 21 '10 #14
thanks again, NeoPa.

I haven't actually tried this yet, but I was wondering about a specific situation: if the active control is a button. Buttons don't have a value, but since the activecontrolname doesn't throw an error, it will try to save the activecontrolvalue - but attempting to do so on a button should throw an error, i think? Wouldn't erroring during the attempt to write the activecontrolvalue cause problems in the if statement that controls recording and resetting - thus causing the database to never close if a button remains the active control?

...

Okay, i tried it. the error it throws when a button is selected it 438. I'll just add that after the write and it'll be fine.

Thanks again for all your help!
Dec 21 '10 #15
Logging out the user/customer(CX) gets them out of the database thus unlocking it and allowing others to get into it. I've had 3 different jobs where I've had at times to log someone off so that other CX can use a file or database.

Also If I remember correctly there's a way using ASP to interface the db. You could create a web-app this way and the only thing that has it locked is the server hosting it.
Dec 21 '10 #16
NeoPa
32,556 Expert Mod 16PB
Sorry for the delay responding.

I think your idea is actually a very good one. There is a potential loophole there if an operator is continually working on data on the same form (particularly if there are only a few controls on it).

After line #29 you can add an If statement just like the preceeding ones that checks for Err = 438 and sets that variable (ActiveControlValue) to either a specific string or possibly even Null. That should work nicely for you.
Dec 24 '10 #17

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

Similar topics

8
by: ACE FAN | last post by:
Hi, I;m a newbie trying to get through some examples in VS2003. I'm trying to open a small Access database using ADO.NET in an ASP.NET app usinig an oleDBConnection. I get the following error...
1
by: Steve Amey | last post by:
Hi all In my .NET application (maybe run as a service), is there a way to know when my computer is locked? I want to write an app that logs when the computer has started and when it has been...
4
by: RSH | last post by:
I am trying to figure out how I can trap the Closing Event that occurs when a user attempts to close the window by clicking on the red"X". I tried this code which I found online but nothing...
10
by: Daniel | last post by:
How can i break my access 2000 VBA project password ? it has been locked and i forget the password. Pls help. Thanks. Daniel
4
by: rdemyan | last post by:
I'm using code from the following web page to open the API Browse Folder dialog http://www.mvps.org/access/api/api0002.htm It all works fine. But if the dialog box is open and the user closes...
2
by: rdemyan via AccessMonster.com | last post by:
I have a custom message form that I want to display when the user shuts down my app. Some clean up needs to be done during shutdown and I want to display this form and then display various...
3
by: ksarkies | last post by:
Hi This is a "problem" I've been battling for many days and haven't been able to understand; various postings I've come across on the Internet seem to not quite provide the answer. We have a...
0
by: Ricardo Luceac | last post by:
Hi all... I'm trying to do a program to control my lan house, and I need to control the access of a user by the time he paid. For example, when the user pays I unlock the computer to him, and...
2
emibt08
by: emibt08 | last post by:
Hi, I have an application that I recently revised. It transfers data between 2 programs, including files as well as small data chunks. I never had a problem (got garbage at the other side) or...
7
by: bigukfan | last post by:
I have an application using multiple Forms, all unbound. The main Form enables users to select which other Forms they want to use, only one at a time, all Modal. I don't want users to close Access...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.