Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Location
    Prineville, OR
    Posts
    4

    Unanswered: Automatic User Logout

    Can anyone tell me if there is a way to do an automatic logout from Access due to user inactivity? I am using the standard Access security set up but cannot find a way to shut down Access. I understand there are timer events but do not know how or where to place it. Optimally I would like the database logon screen to just redisplay after xx minutes of inactivity so the user or new user could just re-enter their logon and password. I have searched the archives without any luck.

    Thanks in advance for any help.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    Well... I suppose you could try this....

    Set the KeyPreview property for your main form (or any form that will become active) to Yes. This property is located directly under the OnKeyPress event in the properties window.

    Next, place the following line of code into the OnKeyPress event of your main form (or any form that will become active) as shown below:
    Code:
    Private Sub Form_KeyPress(KeyAscii As Integer)
       Me.TimerInterval = 60000
    End Sub
    Next, place the following line of code into the MouseMove event for the Details section of your main form (or any form that will become active) as shown below:
    Code:
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Me.TimerInterval = 60000
    End Sub
    Now....with all the above in place, you can put the code below into the OnTimer event of your main form (or any form that will become active). It should look something like....
    Code:
    Private Sub Form_Timer()
        'Make sure the TimerInterval property
        'is set to 60000 (1 minute).
        
        Static Tme As Integer     'Variable to hold the number of Intervals passed by.
        Tme = Tme + 1              'Increment Timer intervals.
        If Tme = 5 Then             'When 5 minutes is reached then execute.
           DoCmd.Quit                'Quit Database.
           '    OR
           'DoCmd.OpenForm "Password Form"
           'DoCmd.Close acForm, "myMainForm"
        End If
    End Sub
    Notice in the above code, we use a Static variable (Tme) to count the number of times the OnTimer event has fired (been processed). This is done because we need to have our timer handle minutes. The form's timer interval can only be set between 0 and 65,535 milliseconds and knowing that 1,000 milliseconds = 1 second, we can quickly see that 60,000 milliseconds (which equals 1 minute) is very near 65,535 limit. By setting our form's timer interval to 60,000 (1 minute) we add up the number of times the OnTimer event is fired. When the times fired (held in the variable Tme) eguals the number of minutes we want, which in our example is 5 minutes, then we process the code held within the conditional If statement. In this case, when 5 minutes have expired, close the database.

    The Me.TimerInterval = 60000 code line located within the KeyPress and MouseMove events resets the Form's timer whenever it is processed. That is, whenever the mouse pointer is moved across a open or blank portion of the form the MouseMove event is fired thus reseting the Form's timer. Consequently, when a user types data into a TextBox or uses the keyboard, the Form's KeyPress event is fired which once again, resets the Form's timer. Please remember to make sure the KeyPreview property for your Form(s) is set to Yes.

    Hope this helps a little

  3. #3
    Join Date
    Jan 2004
    Location
    Prineville, OR
    Posts
    4

    Smile Thanks

    This helps more than just a little. Thanks.

    Since you have been so helpful, one more question along this line 80)

    Since I set up security using the User Level Security Wizard, do you know what form name (if there is one) to open the standard logon form generated by the security wizard? Using the DoCmd.Quit works great but would be nicer if I could redisplay this logon screen.

    Again, thanks for all your help.

  4. #4
    Join Date
    Feb 2004
    Posts
    2
    Hi, I'm new here and somewhat of a rookie, so go easy on me!

    I was actually in search of the answer that CyberLynx gave and it works great for a few of my applications. I want to go a step further, however.

    My current issue is if a user is in the form where the code lies but is actually entering data into a subform, the main form does not recognize that activity and shuts down after x amount of time. Is there a way to have that code either deactivated while the user is on the subform, or to have it cover both the form and subform?

    Thanks in advance for any help offered....

    Patrick

  5. #5
    Join Date
    Feb 2004
    Posts
    142
    Parent.TimerInterval = 60000 in the same two events in the subform will most likely work. If Parent dosen't work then reference the main form explicitly.
    KC

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Originally posted by forpat
    Hi, I'm new here and somewhat of a rookie, so go easy on me!

    I was actually in search of the answer that CyberLynx gave and it works great for a few of my applications. I want to go a step further, however.

    My current issue is if a user is in the form where the code lies but is actually entering data into a subform, the main form does not recognize that activity and shuts down after x amount of time. Is there a way to have that code either deactivated while the user is on the subform, or to have it cover both the form and subform?

    Thanks in advance for any help offered....

    Patrick
    Place the same idea (code) into the actual form which makes up your SubForm (look in the Forms section of the database window, select the subform then select Design View).


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •