Originally Posted by Bob Bedell
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
|