Access Multi User Topics

Table Topics | Queries and Recordsets | Form Topics

Report Topics | Module Code and APIs | General Issues

General

Build an Automatic User Log Off Procedure in Your MulitUser Application




More to Come…. .

© 1996-97 ATTAC Consulting Group



















Back to the Tips List

Build an Automatic User Log Off Procedure in Your MulitUser Application
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:

  1. Create a small form with no controls on it. Leave the form as sizeable, non-popup, non-modal form.
  2. 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).
  3. 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.
  4. 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
    
    
  5. 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:
  1. 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.

  2. 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.

  3. 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.

Back to the Tips List