User Object
Description
A User object represents a user account that has access permissions when a Workspace object operates as a secure workgroup (Microsoft Jet workspaces only).
Remarks
You use User objects to establish and enforce access permissions for the Document objects that represent databases, tables, and queries. Also, if you know the properties of a specific User object, you can create a new Workspace object that has the same access permissions as the User object.
You can append an existing User object to the Users collection of a Group object to give a user account the access permissions for that Group object. Alternatively, you can append the Group object to the Groups collection in a User object to establish membership of the user account in that group. If you use a Users or Groups collection other than the one to which you just appended an object, you may need to use the Refresh method.
With the properties of a User object, you can:
- Use the Name property to return the name of an existing user. You can't return the PID and Password properties of an existing User object.
- Use the Name, PID, and Password properties of a newly created, unappended User object to establish the identity of that User object. If you don't set the Password property, it's set to a zero-length string (" ").
The Microsoft Jet database engine predefines two User objects named Admin and Guest. The user Admin is a member of both of the Group objects named Admins and Users; the user Guest is a member only of the Group object named Guests.
To create a new User object, use the CreateUser method.
To refer to a User object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:
[workspace | group].Users(0)
[workspace | group].Users("name")
[workspace | group].Users![name]
Properties
Name property, Password property, PID property.
Methods
CreateGroup method, NewPassword method.
See Also
CreateUser method.
Specifics (Microsoft Access)
You can create User objects to establish and enforce permissions for Microsoft Access database objects as well as for Data Access Objects. For example, you can set security for forms, reports, macros, and modules.
A User object has a Name property that you can use in setting permissions for a Container or Document object. For example, you can assign the value of a User object's Name property to the UserName property of a Container or Document object. You can then set the Permissions property of the Container or Document object to establish permissions for the user defined by the UserName property. Or you can read the Permissions property to determine existing permissions for that user.
Example
See the Group object example.
Example (Microsoft Access)
The following example creates a new User object and appends it to the Users collection of a Workspace object. It then creates a new Group object and appends it to the Groups collection of the Workspace object. The new User object is also appended to the Users collection of the Group object. The new user is then given read-data permissions on tables.
Note that in order to assign users to groups, you must either append a User object to the Users collection of a Group object, or append a Group object to the Groups collection of a User object. It doesn't matter which option you choose; either will result in the specified user being included in the specified group.
Note When programming security, you should avoid including password and PID information in your code. The following example is intended for demonstration purposes only.
Sub NewTablesUser()
Dim wsp As Workspace, dbs As Database
Dim usr As User, grp As Group, usrMember As User
Dim ctr As Container, doc As Document
' Return reference to default workspace.
Set wsp = DBEngine.Workspaces(0)
' Return reference to current database.
Set dbs = CurrentDb
' Create User object and append to Users collection
' of Workspace object.
Set usr = wsp.CreateUser("Chris Jones", "123abc456DEF", "Password")
wsp.Users.Append usr
' Create Group object and append to Groups collection
' of Workspace object.
Set grp = wsp.CreateGroup("Marketing", "321xyz654EFD")
wsp.Groups.Append grp
' Append new User object to Users collection of new Group object.
Set usrMember = grp.CreateUser("Chris Jones")
grp.Users.Append usrMember
' Refresh Users collection of Group object.
grp.Users.Refresh
' Return Container object.
Set ctr = dbs.Containers!Tables
' Set UserName property of Container object.
ctr.UserName = usrMember.Name
' Add retrieve permissions for new user on all tables.
ctr.Permissions = ctr.Permissions Or dbSecRetrieveData
Set dbs = Nothing
Set wsp = Nothing
End Sub