Identifying Users

In your multiuser application, you may want to programmatically 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 Microsoft Jet user-level security, another requires you to maintain your own user information, and another requires using utilities on the CD-ROM included with this book.

When you establish user-level security for your database, you force the user to log on to your application with a predefined user name and password. The user name is then available to your application through the UserName property of the Workspace object. The following procedure writes the user’s name and the current date and time to fields. In this example, strDbPath is the path to the database.

Dim dbs As Database, rst As Recordset

Set dbs = OpenDatabase(strDbPath)
' Open recordset.
Set rst = dbs.OpenRecordset("AuditTrail")
With rst
	' Add new record.
	.AddNew
	' Write name of current user to table.
	!UserLastModified = Workspaces(0).UserName
	' Write time to table.
	!DateLastModified = Now
	.Update
End With

See Also For more information about users and passwords, see Chapter 10, “Managing Security.”

If you don’t want to implement security, but still want to identify users, you can have your application prompt the user for a name and password at startup and store those values in code variables or a temporary table. This way, you still have access to the user’s name, but don’t have to implement a secured database.

A new (currently unsupported) way to get this information is to use the graphical 32-bit-only Ldbview.exe or programmatic 32-bit Msldbusr.dll utilities. These are found on the CD-ROM that comes with this guide.

See Also For information about how to use Ldbview.exe and Msldbusr.dll to view information about users, see the “Understanding Microsoft Jet Locking” white paper in the Papers folder on the companion CD-ROM. Its file name is Jetlock.doc.