Page 1 of 4 123 ... LastLast
Results 1 to 15 of 47
  1. #1
    Join Date
    Aug 2006
    Posts
    559

    Unanswered: Countdown and logout

    So I've been doing some research on the web and found a few examples of how to force-logout people from a database in Access. The examples aren't that bad. I tried one of them, with no luck, even set the timer for 30 seconds.

    I figure putting a "OnTimer" event on my main form / switchboard, which will detect inactivity within the database after like 5 minutes, figure that's a decent time.

    What I'm trying to do is:

    1. Detect the inactivity within the database.
    2. When inactivity is detected, open a form (frmForceLogout) that I made.
    3. This form has / going to have a countdown timer as soon as I figure that out too! / which counts down from 2 minutes to automatically logging out the user from the db completely.
    4. Two command buttons are on the form. The first says "Yes", second "No"
    Respectively a question above them says, "If you would like to logout of the database now, please click "Yes". If you wish to continue working in the database and cancel the force-logout, please click "No"."

    Can anyone offer some assistance with this?

    The code I found for the logout is:

    Code:
    Private Sub Form_Timer()
    
       
        ' IDLEMINUTES determines how much idle time to wait for before
        ' running the IdleTimeDetected subroutine.
        Const IDLEMINUTES = 30
    
        Static strPrevControlName As String
        Static strPrevFormName As String
        Static sngExpiredTime As Single
    
        Dim strActiveFormName As String
        Dim strActiveControlName As String
        Dim sngExpiredMinutes As Single
    
        On Error Resume Next
    
        ' Get the active form and control name.
    
        strActiveFormName = Screen.ActiveForm.name
        If Err Then
            strActiveFormName = "No Active Form"
            Err = 0
        End If
    
        strActiveControlName = Screen.ActiveControl.name
            If Err Then
            strActiveControlName = "No Active Control"
            Err = 0
        End If
    
        ' Record the current active names and reset sngExpiredTime 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 (strPrevControlName = "") Or (strPrevFormName = "") _
            Or (strActiveFormName <> strPrevFormName) _
            Or (strActiveControlName <> strPrevControlName) Then
             strPrevControlName = strActiveControlName
             strPrevFormName = strActiveFormName
             sngExpiredTime = 0
        Else
            ' ...otherwise the user was idle during the time interval, so
            ' increment the total expired time.
            sngExpiredTime = sngExpiredTime + Me.TimerInterval
        End If
        
        ' Does the total expired time exceed the IDLEMINUTES?
        sngExpiredMinutes = (sngExpiredTime / 1000) / 60
        If sngExpiredMinutes >= IDLEMINUTES Then
            ' ...if so, then reset the expired time to zero...
            sngExpiredTime = 0
            ' ...and call the IdleTimeDetected subroutine.
            IdleTimeDetected sngExpiredMinutes
        End If
    End Sub
    
    Sub IdleTimeDetected(sngExpiredMinutes)
         ' Enter the command or macro that you want to run when the time expires
         ' Also runs a message box showing the period of inactivity
         ' To just close the app, add "DoCmd.Close" after the message box
          ''  DoCmd.Close
            'DoCmd.Close acForm, "frm_login"
          '''  DoCmd.Close , ""
          '''  DoCmd.OpenForm "frm_login", acNormal, "", "", , acNormal
             
       '''Dim strMessage As String
       ''''strMessage = "No user activity detected in the last" & vbCrLf
       '''strMessage = strMessage & sngExpiredMinutes & " minute(s)!"
       '''MsgBox strMessage, vbInformation, "User Has Been Logged Off!"
        
    End Sub

  2. #2
    Join Date
    Feb 2007
    Posts
    348
    reset the timer at the after update event?

  3. #3
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by starkmann
    reset the timer at the after update event?
    Reset the 'inactivity timer', yes, I'll have to do that if the user selects "No" and goes back into the database.

    I'm going to take a look at a few more examples I've found and see if I can figure out what they did.


    **Like the attachment, it's the best I've found so far and some thing like I want to do. But he's got no 'OnTimer' events going as far as I can see so I'm going to print the code for the project and see if I can make sense of it.
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2007
    Posts
    348
    mmm, not really what I was thinking.
    Set the timer on your switchboard or whatever and just set a timer = 0 type code whenever any other form recieves and update, pass the news to the switchboard and the timer is reset.
    Then if your timer hits the magic number docmd.openfrm "autologoutfrm" or whatever. Have it's timer begin. The on click event for your Don't Log out button is to reset the app timer and close the form.Otherwise, your logout timer hits zero or you click Log me out and you run a sub that says application.close.

    I think that meets your needs 'cause it looks like you have the code for the timer already.

    Or am I totally missing the point again, cause I do that.

  5. #5
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    I've successfully used this:

    http://www.peterssoftware.com/isd.htm
    Paul

  6. #6
    Join Date
    Aug 2006
    Posts
    559
    Paul,

    I've seen that one, downloaded it. I'm looking at that one and the one that I uploaded here. Well, I kind of took the background (red & yellow diaginals) of the one I uploaded and put it in the form that I made. I liked it plus, like the guy who developed that one, I figure that the users of my db can't figure that it is not a bad thing when that comes up.

    I'm just trying to figure out how I can make it work now. I'm thinking about making th timer activate on the Main Menu form but maybe also in the 'logon' form incase a user double-clicks the db shortcut but doesn't do anything more than that.

    Can I run the same code twice? or will it create errors within the DB?

  7. #7
    Join Date
    Aug 2006
    Posts
    559
    Alright.... I'm trying to incorporate this, the "Auto-Logout" that I uploaded in this post, into my db. I've kind of set everything up the same way although I don't understand what the code below is doing. I don't have a table, 'tblVersionServer', like it says so I'm not really sure on how to replace or incorporate it into mine.

    I know it's like the 'countdown' but I don't know or understand why it's pointing back to the table, 'tblVersionServer'. Of if there is just a field that I can add to my main table, one of my tables or create a new one to do the same thing. All I'm trying to do is force logout all the users connected to the database at the time (3min) specified of 'non-activity'.


    Does anyone have a clue? Can help?

    Code:
    Private Sub Form_Timer()
       On Error GoTo Err_Handler
       
       Dim intIMins As Integer
       Dim intISecs As Integer
       Dim fLogout As Boolean
       
       fLogout = DLookup("[LogOutAllUsers]", "[tblVersionServer]")
       
       If fLogout = False Then DoCmd.Close acForm, Me.Name
       
       intIMins = DateDiff("s", Now(), mdat_StartCountdownTime) \ 60
       intISecs = DateDiff("s", Now(), DateAdd("n", (intIMins * -1), mdat_StartCountdownTime))
       
       If intIMins = 2 And intISecs = 0 Then
          Me.Visible = True
       End If
       If intIMins = 1 And intISecs = 0 Then
          Me.Visible = True
       End If
       If intIMins = 0 And intISecs = 20 Then
          Me.Visible = True
       End If
       
       If intIMins <= 0 And intISecs <= 0 Then
          DoCmd.Quit
       Else
          On Error Resume Next
          Me.txtMinsSecs = " " & intIMins & "  minutes and  " & intISecs & "  seconds "
       End If
       
       
    Exit_Here:
       Exit Sub
    Err_Handler:
       MsgBox Err.Description, vbExclamation, "Error"
       Resume Exit_Here
    End Sub
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2006
    Posts
    559
    Hmm... I think I'm going to start all over with this countdown - force logout deal cause it's not working any way that I've tried it.

    Oh well, back to the drawing board.

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I guess I'm wondering the point of needing to force a logout. If you're worrried about users continuously having a recordset open on a form in 1 MSAccess interface, there are 3 approaches which I've ever had a need to use....
    1. I make sure the MainForm is not bound to any recordsets and set timers on my data entry forms so they close to the MainForm.
    2. I wrote my data entry forms unbound to any recordsets.
    3. I utilize the vb script I sent you/posted so each user is in their own front-end which pretty much eliminates interface problems in the same mdb with multiple users or user's "locking" an mdb because they sit in it for a long time.

    There are the Windows Keyboard/Mouse Hooks (similar to the MouseHook you have) which detect inactivity but personally, I'd stay away from them to avoid adding unneccessary complication.

    So I guess my question is... what is the necessity and problem at hand for which you need to force a logout?
    Last edited by pkstormy; 06-10-07 at 21:33.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  10. #10
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by pkstormy
    I guess I'm wondering the point of needing to force a logout. If you're worrried about users continuously having a recordset open on a form in 1 MSAccess interface, there are 3 approaches which I've ever had a need to use....
    1. I make sure the MainForm is not bound to any recordsets and set timers on my data entry forms so they close to the MainForm.
    2. I wrote my data entry forms unbound to any recordsets.
    3. I utilize the vb script I sent you/posted so each user is in their own front-end which pretty much eliminates interface problems in the same mdb with multiple users or user's "locking" an mdb because they sit in it for a long time.

    There are the Windows Keyboard/Mouse Hooks (similar to the MouseHook you have) which detect inactivity but personally, I'd stay away from them to avoid adding unneccessary complication.

    So I guess my question is... what is the necessity and problem at hand for which you need to force a logout?
    Paul,

    My reason for force-logging people out... Well, it's principle. Also, since people on the network are supposed to restart their machines daily, I figure it'll help to properly close out connections to the back-end of the database.

    Also, people have a habit of leaving their computers locked so I want to make sure that they are logged off for back-up purposes especially since this database is going to be used on a Department of Defense network where really anyone above where I work can scan, restart and shutdown computers remotely (which I hate) but I can't do anything about.

    Bryan

  11. #11
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Bryan,

    Ok....I understand the principle thing. Are you looking for code to log people out of their machine or just out of the TaskTracker program?

    I assume you have a "Development" drive and a "Deployment" drive. The "Development" drive will have your TaskTracker working code where you make copies of it and then get into it to make changes (or you use visual source-safe). I made it a habit of making a copy every time I got into the frontend *.mdb so if I didn't like the 4 hours of coding I did or something happened and the frontend got corrupted, I had a backup of it. Nothing worse than losing a day or even a weeks worth of coding in your frontend!! And it takes a few seconds to do this so there really isn't an excuse not to "copy","paste" the *.mdb file!

    The "Deployment" drive is then the copy which people are using it (I'd recommend making an mde on your "Development" drive and then copy this to the "Deployment" drive for people to use.) An *.mde file is much better for people to utilize verses an *.mdb file.

    As far as backing up, the key file is your backend data *.mdb which has all the tables in it, correct? If the frontend gets destroyed, you can easily copy a new frontend from your "Development" drive. If the backend get's destroyed, then you need to restore from backup. This is where SQL Server would really be handy to have as you can do "tranlog" backups of the data tables every 15 minutes or on the hour, schedule your own backup plan which you could restore from without having to go to the network backups, and is a lot better for maintaining multi-user databases (and I believe you can now get SQL Server Express for free.) If this data is critical data, I'd recommend looking into it as it's not that difficult of a program to learn and you can very easily upsize your MSAccess tables to SQL Server via the wizard in MSAccess. I've always hated relying on the network backups as whenever I went to the network guys to have a file restored, they would either tell me it would take a while for them to search the tape drive to restore it, or they would tell me they could only restore the file from such a such date.

    You may want to run it through a disaster plan where you mimick that the backend MSAccess file getting destroyed and see if the network guys can get the file restored for you! Waiting for it to actually happen can be detrimental!! I always "tested" these kind of scenarios to see how they would work in case of an actual emergency. After all, what good is it if the network guys tell you they can only restore your backend MSAccess data tables from a week ago? Who get's to tell the end users they need to re-enter a weeks worth of data (and who usually gets the blame??) But don't let them know ahead of time. Just ask them if they are backing up your backend file and then wait a week or so and spring it on them as a surprise telling them your file got corrupted and you need to restore it. You might be surprised at the results (and might not). As you can probably tell, I have little faith (maybe because I've seen so many problems with restoring from network backups and relying on this.)
    Last edited by pkstormy; 06-11-07 at 11:16.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  12. #12
    Join Date
    Aug 2006
    Posts
    559
    Paul,

    All that you said, well, except for the guys backing it up / recovering it for me . I found , don't recall if you posted it, but an 'autobackup' for the db which is another reason why I wanted to force-loggoff people.

    Other than that, the development drive that you are saying, I have the db currently on 2 USB drives and 3 hard disk drives on two different computers (home and work). it will stay on those and be put on a different, network drive, for people to actually use once it's finished.

  13. #13
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by pkstormy
    Bryan,

    Ok....I understand the principle thing. Are you looking for code to log people out of their machine or just out of the TaskTracker program?
    I'm just looking to log people out of the Task Tracker program so that autoback-ups can be done without having people accessing the tables and causing issues. Though I believe it can be done without doing the force-logout, I just think forcing them out after a period of like 3minutes of inactivity should be done to teach them they can't stay connected forever. **THEY HAVE A HABIT OF DOING THIS ALL THE TIME**

  14. #14
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Bryan,

    But get in the habit of copying, pasting your mdb often before you get into each day! It only takes a few seconds!

    And test-out your network backups by running it through a disaster scenario (and don't tell the network guys you're doing it!) - Just ask them if they are backing up the file and wait a week or so.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  15. #15
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I can't stress testing out the network backups enough.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

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