Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27
  1. #16
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Yes its similar code.


    My point was that detecting inactivity in one user & closing their copy of the FE is a separate issue to kicking out everyone for maintenance purposes
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  2. #17
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    I know, but based on the OP's original post, and despite the thread title, seemed like this is what they were after and would have saved a trip to the client site. I've been using the MS idle routine for years (I think I might have got it from the Access 97 bible book ).
    Cheers,

  3. #18
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for all the suggestions. I've implemented the most agreed-upon method with a few changes.

    Instead of using static variables, I created a Public function (GetIdleTime) in a module. I also declared Public variables for AppIdleTime (Long), ActiveFormName (String) and ActiveControlName (String) in the same module.

    This function returns a Long Integer indicating the total idle time (which may be 0 or not, depending on the comparison of current active form/control with prior values).

    This way, the Form.Timer code is short and to the point, calling the function as a "black box" function. I decided on public module-level variables instead of Static variables in the function, in case I wanted to reference the form or control name in the calling code when timeout number is exceeded.

    Now that this code works, I have a related question:

    In case the user's PC goes to sleep due to inactivity, will the Form.Timer event even fire at all, or is everything suspended when the PC sleeps? That would make all of this code useless, wouldn't it?

    Thanks...

  4. #19
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Only way to know the answer to that with what you've done is to test it?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #20
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by Micron View Post
    Only way to know the answer to that with what you've done is to test it?
    Well, yeah...

    I was just curious if anybody had seen that behavior. I will do the testing, then if the timer doesn't keep running, I will post either here or on a new thread to see about finding a solution to that. But it seems like a deal breaker to put timeout code in the application, then find out it doesn't work because the PC went to sleep.

    Thanks...

  6. #21
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    So at least on my Dell XPS laptop, when I put it to sleep the timer is suspended for as long as the laptop is asleep. When I wake it up again, the timer happily starts going again, and the app quits when it hits the maximum inactivity time.

    This is a big problem for this use-case, right?

    Not sure if a user's PC has a screen saver time, and the screen goes blank, that is the same thing as when I put mine to sleep. If not, I may still be OK. But if it is the same, how can you kick them off if their timer just stopped running? The app could be sitting there for 10 hours and not exitting because the timer thinks it's been 5 minutes.

    Can't think of a work-around for this.

  7. #22
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716
    ?? I don't know the underlying details.
    But I did Google with the search parameters below. You may repeat the search and review the responses for some insight. Let us know if you find a solution. Good luck.

    ms access is there a way to keep timer active if user pc goes to sleep

  8. #23
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Quote Originally Posted by orange View Post
    ?? I don't know the underlying details.
    But I did Google with the search parameters below. You may repeat the search and review the responses for some insight. Let us know if you find a solution. Good luck.

    ms access is there a way to keep timer active if user pc goes to sleep
    Thanks Orange. None of those articles seemed to answer this specific issue. Still wondering if there is a way to keep track of how long the program is idle if the PC goes to sleep.

  9. #24
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    According to post 8 and later here, it should work. Perhaps there is a clue wrt post 15.
    https://www.access-programmers.co.uk...s-a-pc.304143/

    One test I'd suggest just to make sure the timer event doesn't actually run is to invoke a message box instead, put pc in sleep mode, wait the duration and see if the msgbox popped up - just to be sure it's not some other cause that makes it appear to not work.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #25
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Latest testing indicates the timer keeps running if the user taps Ctrl-Alt-Delete and chooses "Lock". Therefore the code to close the database will continue to work.
    I believe this option happens automatically when the screen saver pops on on a desktop PC. Probably not on most laptops, I believe they go to sleep after a time of no activity.

    If the user chooses "Sign Out", it will close the database anyway.
    If the PC goes to Sleep as opposed to being locked, the timer stops working, and therefore the inactive user code will NOT work.

  11. #26
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    So here is the solution I've implemented to exit the front-end database after a timeout. I put the following code in a module. As mentioned earlier, I opted to use public variables in the module instead of Static variables in the function, so the form and control names could be used elsewhere if desired.

    Code:
    'For detecting idle timePublic appIdleTime          As Long
    Public activeFormName       As String
    Public activeControlName    As String
    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure     : GetIdleTime
    ' Author        : RMittelman@gmail.com
    ' Purpose       : Gets the total time the application has been idle
    '
    ' History       :   5/22/2022   Original version
    '
    ' Parameters    :
    '   interval    : How often to check for idle status
    '                   Typically send the form's TimerInterval in milliseconds
    '
    ' Returns       : Long Integer indicating total milliseconds application is idle
    '
    ' Notes         : Requires these Public variables declared in this module
    '                   appIdleTime         As Long
    '                   activeFormName      As String
    '                   activeControlName   As String
    '
    '                 In a form which is always open (even if hidden):
    '                   - Set Form.TimerInterval to how often to check for inactivity
    '                     - ex: for 10 seconds, use 10,000
    '                     - If not using this functionality, leave TimerInterval at 0
    '                   - In Form_Timer event, put the following:
    '                       Dim idleMinutes As Long
    '                       idleMinutes = GetIdleTime(Me.TimerInterval) / 60000
    '                       If idleMinutes > TempVars!TimeoutMinutes Then
    '                           MsgBox "You've exceeded idle time"
    '                           ' (instead of MsgBox, put code to close down app)
    '                       End If
    '                   - If Form.TimerInterval is 0, this code is never executed
    '
    '---------------------------------------------------------------------------------------
    '
    Public Function GetIdleTime(interval As Long) As Long
    
    
        Dim newFormName     As String
        Dim newControlName  As String
        
        On Error Resume Next
        newFormName = Screen.ActiveForm.Name
        If Err Then
            newFormName = "No Active Form"
            Err = 0
        End If
        
        newControlName = Screen.ActiveControl.Name
        If Err Then
            newControlName = "No Active Control"
            Err = 0
        End If
        
        ' if first time running, or form/control changed, start idle time over
        If (activeFormName = "") Or (activeControlName = "") _
        Or (newFormName <> activeFormName) _
        Or (newControlName <> activeControlName) Then
                 
            activeFormName = newFormName
            activeControlName = newControlName
            appIdleTime = 0
            
        ' otherwise, update idle time
        Else
            appIdleTime = appIdleTime + interval
        End If
        
        GetIdleTime = appIdleTime
    
    End Function
    The following code is in either a hidden form, or in my case a base form which is visible and shows the app icon. I use a TempVar to store how many minutes to wait before closing the database, but any variable will do. The "Quit" macro already exists in my database, and is called when user clicks the Quit button.

    Code:
    Private Sub Form_Load()
    
        ' if we have a setting for timeout, start the timer for every minute
        If Nz(TempVars!TimeoutMinutes, 0) > 0 Then
            appIdleTime = 0
            Me.TimerInterval = 5000
            Me.lblIdleTime.Caption = "Idle time:  0.00 minutes (database will close after " & TempVars!TimeoutMinutes & " minutes)"
        End If
    
    End Sub
    
    Private Sub Form_Timer()
    
    
        Dim idleMs      As Long
        Dim idleMinutes As Double
        Dim msg         As String
        
        idleMs = GetIdleTime(Me.TimerInterval)
        idleMinutes = idleMs / 60000
        msg = "Idle time:  " & Format$(idleMinutes, "0.00") & " minutes (database will close after " & TempVars!TimeoutMinutes & " minutes)"
        Me.lblIdleTime.Caption = msg
        Debug.Print msg ' Optional
        DoEvents
        If idleMinutes > TempVars!TimeoutMinutes Then
            DoCmd.RunMacro "Quit"
        End If
    
    
    End Sub
    Colin, I am not currently using cursor position, just form and control names. Please advise the importance of also using cursor position. I presume Windows APIs are used for the cursor position, and it's returned using a POINTAPI structure, right?

  12. #27
    rjgriffin46 is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2014
    Location
    New Jersey
    Posts
    128

    Detect and Close Front End Code Questions

    I'm not well versed in VBA coding so I have some questions about this code:


    1. When you state "I put the following code in a module" I think I understand a module can be created in VBA that is not associated with a form or another object. Is this what you mean?
    2. Are the first 2 codes in this same module?
      1. Code that starts with "'For detecting idle time"
      2. Code that starts with "' Procedure : GetIdleTime
        1. Are these two sets of codes together in the same module?
        2. What name do you recommend for the module?

      3. "Code is in either a hidden form, or in my case a base form."
        1. What is a base from?
        2. It starts with: "Private Sub_Form Load().
        3. Is this code placed in the On Load event?


    3. In database options, I have "Main Form" as the Display form that opens when the database is opened. If the hidden or base form is supposed to always be open, should it be opened via the Main Form On Load event or vica versa?

    4. For the "Quit" macro it looks like I'd just need the "QuitAccess" action...?

    5. Will the following situations register as inactive in an open front end if the user:
      1. Leaves the cursor on a control in an open form.
      2. Leaves the cursor anywhere in an open report, in Report or Print Preview mode.
      3. Leaves the cursor anywhere in an open query, in Report or Print Preview mode.
      4. What other situations might not detect idle time?



    Thanks, Bob Griffin

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-28-2018, 11:42 AM
  2. Database Design to Maintain Inactive Employee Records
    By Tylin in forum Database Design
    Replies: 6
    Last Post: 03-03-2018, 01:11 PM
  3. Replies: 5
    Last Post: 09-01-2014, 12:11 PM
  4. Multi Users Access database gets Inactive
    By drunkenneo in forum Access
    Replies: 3
    Last Post: 11-14-2013, 03:12 AM
  5. should i close inactive forms
    By Mclaren in forum Forms
    Replies: 1
    Last Post: 07-07-2010, 02:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums