Administrators of mulituser database applications often need a way to signal or require that users Log Off an application for maintence, backup or to correct an error in the system. Access itself has no built in way to facilitate this functionality.
However, creating a method to request or automatically log off users is not too difficult to develop in an Access database using a hidden startup form as described in the following steps:
- Create a small form with no controls on it. Leave the form as sizeable, non-popup, non-modal form.
- Set the TimerInterval property to 300000 to cause the OnTimer event to fire every 5 minutes (you can lengthen or shorten this interval as necessary).
- Create a table in your server db, which only the administrator can write to, but every user can read. Create only one field called LogOff with a yes/no datatype. Add a value of No for the first and only record that will exist in this table.
- In the OnTimer property of the form discussed earlier, add code which will query the value of your Log Off table value, and issue a message to the user to log off. For more advanced capabilities you can make your code warn the user first and then if the user doesn't log off, automatically log them off. Here's a sample: (Note: an underscore _ means the line continues on the next line.)
Private Sub Form_Timer()
Static MsgSent as Integer
Dim LogOff as Integer
Dim Db as Database
Dim LO as Recordset
Set Db = CurrentDB() 'Note the table must be attached
'for CurrentDb() to work or use a
'connect string to the server db.
Set LO = Db.OpenRecordset("tblLogOff" , _
DB_OPEN_SNAPSHOT)
LO.MoveFirst
LogOff = LO!LogOff
LO.Close
Db.Close
If LogOff = True Then
If Not MsgSent Then
MsgBox "The Application will be shutting down in _
one (1) minute for maintenance, please log off _
immediately."
Me.TimerInterval = 60000 'change to one minute
MsgSent = True
Else
Application.Quit 'Log them off now.
End If
End If
End Sub
When you start the application, add a command to your autoexec macro to open this form in a hidden status.
There are a few options in implementing this method which you may want to consider:
- Rather than checking for a value in a table in the server db, you may want to have your timer event check for the existance of a
small text file which the administrator would place in a specified directory on the server. This has an advantage of not requiring
the client app to query the server db in the event that the server db has somehow become corrupt and the query to the LogOff table fails.
You can simply use the Access Dir() command to check for the existance of this file.
- Rather than using a message box to issue the message to log off you may want to create a second message "form" which you pop up
and close after a short period of time automatically using its timer code. The advantage to this is that message boxes are modal windows
and they cause your code to suspend until the user closes them. So if the user is away from their workstation when the "Log Off"
command is issue, if they don't click on the the message box button, the code never continues.
- Add a function similar Log Off function from the timer event code behind the form to a general db module so that you can run the code from your autoexec macro, prior to reattaching tables, in order to query the
value of log off when the user attempts to start the database. This could eliminate their ability to attach to the server data while the maintenance is be run.
|