Previous Page

Identifying Users

In your multiuser application, you may want to identify the user currently logged on to the system. This is useful for administrative functions, such as storing the user's name with edited records to create an audit trail. Several methods are available to achieve this functionality. One involves user-level security, and another requires you to maintain your own user information.

If you establish user-level security in your database, users must log on to your application with predefined user names and passwords. The user names are then available to your application through the UserName property of the Workspace object. The following function writes audit information to a record. It is assumed that the recordset rst includes the fields UserLastModified and DateTimeLastModified.

Function WriteAuditTrail(rst As Recordset) As Integer
   On Error GoTo ErrorHandler
   ' Edit the current record in the recordset.
   rst.Edit
   rst!UserLastModified = Workspaces(0).UserName
   rst!DateTimeLastModified = Now
   rst.Update
ErrorHandler:
   Select Case Err
      Case 0
         ' conSuccess is defined at the module level as a public constant
         ' of type Integer with a value of zero.
         WriteAuditTrail = conSuccess
         Exit Function
      Case Else
         MsgBox "Error " & Err & ": " & Error, vbOKOnly, "ERROR"
         WriteAuditTrail = Err
         Exit Function
   End Select
End Function

If you don't want to establish user-level security, but still require user name functionality, you can have your application prompt the user for a name and password at startup and store those values in code variables or in a temporary table. This way, you still have access to the user's name, but you don't have to establish user-level security in your database.

See Also   For information on establishing user-level security in your database, see Chapter 14, "Securing Your Application."

© 1996 Microsoft Corporation. All rights reserved.

Next Page


Casa de Bender