Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 31st, 2014, 04:27 AM
Registered User
 
Join Date: Jan 2014
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Dear Bob,

I know this was quite a while ago, but I would like to thank you for this post. It helped me a lot!
I'm just courious if there is a way to change this code in order to count down by seconds and not just by minutes. Could you kindly help me out here?

Thank you for your time.
~ Maylice

Quote:
Originally Posted by Bob Bedell View Post
Hello,

Here is an approach I picked up from F. Scott Barker. I use a simplified version of his method but its effective. Barker uses some custom database container properties (File->Database Properties->Custom to set a Boolean custom property in the backend db that administrator’s can toggle on and off, and that front-end applications can monitor periodically using a Timer event. If the property is toggled ON, code in the front-end apps executes an Application.Quit statement, after the proper notifications. The problem with this approach is that, if the backend db is corrupted, the db’s custom properties won’t do you any good.

So I’ve just hard-coded the path to the backend db folder to simplify things in what follows. Here are the basic ideas:

1. Give the system admin a means of creating a hidden ‘flag file’ (Logout.flg) in the folder that the backend resides in. (this is done using frmSystemUtilities below)

2. Create a hidden form in all of the frontend apps that is opened from your splash screen when the workstation apps are opened. Code behind the hidden ‘monitor’ form checks periodically for the existence of the flag file using a Timer event. (frmLogoutMonitor below)

3. If the flag file exists (i.e., the admin has initiated a logout), have frmLogoutMonitor open a second form called frmLogoutCountdown. This form notifies users that they will be logged out in, say, 5 minutes, and includes a textbox that counts down the minutes until there application instance will quit.

4. You also need a method of canceling the logout if the admin decides to do so. This can simply be done by toggling the caption property on the command button placed on frmSystemUtilities which the admin uses to initiate the logout.

5. You also need 4 utility routines in a standard module (basGlobalUtilities) to handle the flag file creation and removal, check for its existence, and to check to see if frmLogoutCountdown is already open (i.e., a forces logout is underway), so you can close it if the admin cancels the logout.

*********
frmSplash
*********

Add the following code behind any splash screen to open the hidden monitor form. This form must remain open for the life of the session:

Private Sub Form_Load()

    ' Turn on the monitor form
    DoCmd.OpenForm "frmLogoutMonitor", , , , , acHidden

End Sub

**********
frmMonitor
**********

Set the monitor forms timer interval property to 60000 (1 minute). The monitor form will check for the existence of the flag file once every minute. You can adjust this if performance suffers. Place the following in the monitor forms Timer event:

Private Sub Form_Timer()

    ' Does flag file exist. You are looking for it in the folder
    ' where you backend db resides. If it exists, open the countdown form.
    If LogOutCheck("C:\Temp\Logout.flg") Then
        If Not FormIsOpen("frmLogoutCountdown") Then
            DoCmd.OpenForm "frmLogoutCountdown"
        End If
    Else
        ' If admin cancels logout, close countdown form.
        If FormIsOpen("frmLogoutCountdown") Then
            DoCmd.Close acForm, "frmLogoutCountdown"
            Beep
            MsgBox "The Logout Countdown has been canceled." & vbCrLf & _
                   vbCrLf & "You may go on with your work.", _
                   vbInformation, "Logout Canceled"
        End If
    End If
End Sub

******************
frmLogoutCountdown
******************

Place appropriate notification labels on this form, letting users know that they will be logged out in 5 minutes. Place a textbox on his form named txtMinutesToGo to display the countdown. Set frmLogoutCountdown’s Timer Interval property to 60000 also. Place this code behind frmLogoutCountdown:

Private mintCountDown As Integer

Private Sub Form_Open(Cancel As Integer)
    mintCountDown = 5
End Sub

Private Sub Form_Timer()

   ' Decrement countdown textbox by 1 minute.
   mintCountDown = mintCountDown - 1
   If mintCountDown <= 0 Then
     Application.Quit
   Else
     Beep
     Me!txtMinutesToGo = mintCountDown
   End If

End Sub

******************
frmSystemUtilities
******************

Create a form with a single command button on it. This form can only be accessed with an admin logon. The admin will click this button to initiate/cancel the forced logout. Set the buttons caption to “Log Users Out of System”. Place the following in the command button's Click event:

Private Sub cmdLogInOut_Click()

    If Dir("C:\Temp\Logout.flg", vbHidden) = "Logout.flg" Then
       Call LogoutRemove
    Else
       Call LogOutCreate
    End If

    Call DisplayLogInOut

End Sub

Sub DisplayLogInOut()

   If Dir("C:\Temp\Logout.flg", vbHidden) = "Logout.flg" Then
      Me!cmdLogInOut.Caption = "&Allow Users Into System"
   Else
      Me!cmdLogInOut.Caption = "&Log Users Out Of System"
   End If

End Sub

******************
basGlobalUtilities
******************

Now you just need the utility routines to create and remove the flag file, check to see if it exists, and check to see if frmLogoutCountdown is already open. Place the following in a standard module:

Function LogOutCheck(strBackEndPath) As Integer

   On Error Resume Next
   LogOutCheck = Dir("C:\Temp\Logout.flg", vbHidden) = "Logout.flg"

End Function

Function FormIsOpen(strFormName As String) As Integer

   Dim frmCurrent As Form

   For Each frmCurrent In Forms
      If frmCurrent.Name = strFormName Then
         FormIsOpen = True
         Exit Function
      End If
   Next frmCurrent

End Function

Public Sub LogoutRemove()

    On Error Resume Next
    SetAttr "C:\Temp\Logout.flg", vbNormal
    Kill "C:\Temp\Logout.flg"

End Sub

Public Sub LogOutCreate()

    On Error Resume Next
    ' Create flag file
    Open "C:\Temp\Logout.flg" For Output Shared As #1
    Close #1
    SetAttr "C:\Temp\Logout.flg", vbHidden

End Sub

I think that covers all the bases. Let me know if you need clarification on anything.

HTH,

Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access application exit button generate lock ayazhoda Access VBA 1 June 17th, 2008 10:28 AM
Application.exit() fails to terminate application. saumya General .NET 1 January 4th, 2008 09:50 AM
Exit Application King_ General .NET 0 February 23rd, 2006 10:30 AM
command to exit access?? ihsail Access 5 August 12th, 2005 09:04 AM
Application.Exit() Help rodmcleay C# 2 October 8th, 2003 07:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.