CreateUser Method

Applies To   Group object, Workspace object.

Description

Creates a new User object (Microsoft Jet workspaces only).

Syntax

Set user = object.CreateUser(name, pid, password)

The CreateUser method syntax has these parts.

Part

Description

user

An object variable that represents the User object you want to create.

object

An object variable that represents the Group or Workspace object for which you want to create the new User object.

name

Optional. A Variant (String subtype) that uniquely names the new User object. See the Name property for details on valid User names.

pid

Optional. A Variant (String subtype) containing the PID of a user account. The identifier must contain from 4 to 20 alphanumeric characters. See the PID property for more information on valid personal identifiers.

password

Optional. A Variant (String subtype) containing the password for the new User object. The password can be up to 14 characters long and can include any characters except the ASCII character 0 (null). See the Password property for more information on valid passwords.


Remarks   If you omit one or more of the optional parts when you use the CreateUser method, you can use an appropriate assignment statement to set or reset the corresponding property before you append the new object to a collection. After you append the object, you can alter some but not all of its property settings. See the PID, Name, and Password property topics for more details.

If name refers to an object that is already a member of the collection, a run-time error occurs when you use the Append method.

To remove a User object from the Users collection, use the Delete method on the collection.

See Also   Append method, Delete method, Name property, Password property, PID property, User object.

Specifics (Microsoft Access)

Once you have created a new User object and appended it to the Users collection of a Workspace or Group object, you can verify that the new user exists by examining the Name list box on the Users tab of the User And Group Accounts dialog box. This dialog box is available by pointing to Security on the Tools menu and clicking User And Group Accounts.

Example

This example uses the CreateUser method and Password and PID properties to create a new User object; it then makes the new User object a member of different Group objects and lists its properties and groups.

Sub CreateUserX()

    Dim wrkDefault As Workspace
    Dim usrNew As User
    Dim grpNew As Group
    Dim usrTemp As User
    Dim prpLoop As Property
    Dim grpLoop As Group

    Set wrkDefault = DBEngine.Workspaces(0)

    With wrkDefault

        ' Create and append new User.
        Set usrNew = .CreateUser("NewUser")
        usrNew.PID = "AAA123456789"
        usrNew.Password = "NewPassword"
        .Users.Append usrNew

        ' Create and append new Group.
        Set grpNew = .CreateGroup("NewGroup", "AAA123456789")
        .Groups.Append grpNew

        ' Make the user "NewUser" a member of the
        ' group "NewGroup" by creating and adding the
        ' appropriate User object to the group's Users
        ' collection.
        Set usrTemp = _
            .Groups("NewGroup").CreateUser("NewUser")
        .Groups("NewGroup").Users.Append usrTemp

        Debug.Print "Properties of " & usrNew.Name

        ' Enumerate the Properties collection of NewUser. The
        ' PID property is not readable.
        For Each prpLoop In usrNew.Properties
            On Error Resume Next
            If prpLoop <> "" Then Debug.Print "    " & _
                prpLoop.Name & " = " & prpLoop
            On Error GoTo 0
        Next prpLoop

        Debug.Print "Groups collection of " & usrNew.Name

        ' Enumerate the Groups collection of NewUser.
        For Each grpLoop In usrNew.Groups
            Debug.Print "    " & grpLoop.Name
        Next grpLoop

        ' Delete the new User and Group objects because this
        ' is a demonstration.
        .Users.Delete "NewUser"
        .Groups.Delete "NewGroup"

    End With

End Sub