Automatic logout

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Irv1010

Thread Starter
Joined
Jul 20, 2008
Messages
23
Hi all

I am trying to get my Access 2003 db to log inactive users off after a period of time. Having found something within microsoft support, I have been trying to implement it with no success. I have created a blank form called DetectIdleTime with the following properties:

TimerInterval: 1000
OnTimer: [Event Procedure]

Option Compare Database
Private Sub Form_Timer()
' IDLEMINUTES determines how much idle time to wait before running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 1
Static PrevControlName As String
Static PrevFormName As String
Static ExpiredTime
Dim ActiveFormName As String
Dim ActiveControlName As String
Dim ExpiredMinutes
On Error Resume Next
' Get the active form and control name.
ActiveFormName = Screen.ActiveForm.Name
If Err Then
ActiveFormName = "No Active Form"
Err = 0
End If
ActiveControlName = Screen.ActiveControl.Name
If Err Then
ActiveControlName = "No Active Control"
Err = 0
End If
'Record the current active names and reset ExpiredTime if:
' 1. They have not been recorded yet (code is running for the first time)
' 2. The previous names are different than the current ones
' (the user has done something different during the timer interval).
If (PrevControlName = "") Or (PrevFormName = "") Or (ActiveFormName <> PrevControlName) Then
PrevControlName = ActiveControlName
PrevFormName = ActiveFormName
ExpiredTime = 0
Else
' Otherwise the user was idle during the time interval, so
' increment the total expired time.
ExpiredTime = ExpiredTime + Me.TimerInterval
End If
' Does the total expired time exceed the IDLEMINUTES?
ExpiredMinutes = (ExpiredTime / 1000) / 60
If ExpiredMinutes >= IDLEMINUTES Then
' ...if so, then reset the expired time to zero...
ExpiredTime = 0
' ...and call the IdleTimeDetected subroutine.
IdleTimeDetected ExpiredMinutes
End If
End Sub
Private Sub IdleTimeDetected(ExpiredMinutes)
Application.Quit acQuitSaveAll
End Sub

I also created a Macro called AutoExec as follows:

Action: Openform
FormName: DetectIdleTime
View: Form
Data Mode: Edit
Window Mode: Hidden

My problem is that nothing happens even though I sit and wait for well over the 1 minute. Any ideas?
 

OBP

Joined
Mar 8, 2005
Messages
19,895
If you add an Error trap instead of using "On error resume next" you will see that it is continually cycling through an error.
 

Irv1010

Thread Starter
Joined
Jul 20, 2008
Messages
23
Many thanks for responding again.

I really don't know what you mean by Error trap. Would it be possible for you to give me an example please?
 

OBP

Joined
Mar 8, 2005
Messages
19,895
At the beginning of the Code where you have "On Error Resume Next" change it to
On Error Goto ErrorCatch

As the last lines before the "End Sub" insert

Exit Sub ' quits procedure before encountering the Error routine

ErrorCatch:
MsgBox Err.Description

You will find that it just keeps cycling through the same error message each time the On Timer event tries to run
 

Irv1010

Thread Starter
Joined
Jul 20, 2008
Messages
23
Many thanks again

However, it still isn't working and when I close my switchboard form, I get a message saying "You entered an expression that requires a form to be the active window" this message keeps coming back every 2 seconds.
 

OBP

Joined
Mar 8, 2005
Messages
19,895
Sorry , I didn't mean that it would Fix it, just tell you why it wasn't working.
I will try and take a look at it later to see if I can see what is wrong.
MS and MS help quite often provide VBA code that doesn't work
 

Irv1010

Thread Starter
Joined
Jul 20, 2008
Messages
23
Many thanks. I'll put the db away to bed until I hear back from you. (I could do with a rest from it).
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top