Results 1 to 4 of 4
  1. #1
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24

    Set Program to Close Automatically


    I used the code below that I foundonline for creating a timer that will close the DB when there is no activity,it works great with how it was designed looking for activity with a new form. However, with my DB it needs some adjusting as my DB has a single navigationform with multiple rows of tabs that the users click through for the informationthey are viewing. There are separate forms that they occasionally will select. With this the Active form does not change, thus I need a way for it to call on the active tab of the navigation form. I am still new to coding and I need someone to help me write this the correct way.


    The way this code works is I have a form named Detectidle Time with the text fields txtOpenForm, txtMinutes, and with the below code in the Event On Timer with the Event Timer Interval = 1,000.
    I am assuming I can create a new field (txtCurentTab) to store the name of the current tab in use called from the code below just like the current form is populated into the txtOpenForm. I have tried to write the code, however I feel like I am not telling it how to reference the current tab name correctly.

    I have attached screenshots of the Detectidle Time form, andthe Navigation form that works 90% of my DB.

    Code:
     Option Compare Database
    Private Sub Form_Timer()
        ' IdleMinute determines how much idle time to wait for before
        ' running the Idle Time Detected subroutine.
        Static OldControlName As String
        Static OldFormName 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
        Me.txtOpenForm = ActiveFormName
        
        ActiveControlName = Screen.ActiveControl.Name
        ' 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 old names are different than the current ones
        '       (the user has done something different during the interval).
        If (OldControlName = "") Or (OldFormName = "") _
          Or (ActiveFormName <> OldFormName) _
          Or (ActiveControlName <> OldControlName) Then
           OldControlName = ActiveControlName
           OldFormName = 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?
        '.......................................................CHANGE EXPIRED MINUTES TIME  (ExpiredTime / 1000) / 60.........................
        ExpiredMinutes = (ExpiredTime / 1000) / 60
         Me.txtMinutes = ExpiredMinutes
       ' Me.txtMinutes = Format (ExpiredMinutes, "Standard")
        
       '.......................................................CHANGE EXPIRED MINUTES TIME  >= 10 Then.........................................
        If ExpiredMinutes >= 10 Then
           ' then reset the expired time to zero...
           ExpiredTime = 0
           ' ...quit application
           MsgBox "No activity in last " & "10 minutes", vbCritical, "Terminate Program"
            Application.Quit acSaveYes
    End If
    End Sub
    Attached Thumbnails Attached Thumbnails DetectIdle Time.png   Home Tab with Sub Tabs.png  

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You don't need the Detectidle Time form, move the code and timer settings to your navigation form's Timer event.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    So simple, just needed some outside perspective. Worked great! Thanks

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    You're welcome!
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Disable Program Close Button
    By perryc in forum Forms
    Replies: 9
    Last Post: 04-30-2019, 06:07 AM
  2. Can VBA automatically copy a row in Excel and then close it?
    By bburton12@comcast.net in forum Programming
    Replies: 2
    Last Post: 08-15-2018, 03:51 AM
  3. Replies: 2
    Last Post: 09-23-2015, 09:02 PM
  4. Replies: 6
    Last Post: 10-03-2012, 05:50 AM
  5. Automatically close form in 5 seconds
    By alaric01 in forum Forms
    Replies: 4
    Last Post: 09-21-2010, 04:25 AM

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