>

User Object

Description

A User object represents a user account that has access permissions when a Workspace object operates as a secure workgroup.

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.

Using the properties of a User object, you can:

The Microsoft Jet database engine predefines two User objects named Admin and Guest. The user Admin is a member of the Group object named Admins and Users; the user Guest is a member only of the Group object named Guests.

You can refer to any other User object that you create and append to a Users collection by its Name property setting using this syntax:

Workspaces(n)|Group.Users("name")

To create a new User object, use the CreateUser method.

Properties

Name Property, Password Property, PID Property.

Methods

CreateGroup Method, NewPassword Method.

See Also

CreateUser Method; Appendix, "Data Access Object Hierarchy."

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


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

    Set wsp = DBEngine.Workspaces(0)
    ' Return Database object pointing 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
End Sub