CreateGroup Method

Applies To

User object, Workspace object.

Description

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

Syntax

Set group = object.CreateGroup(name, pid)

The CreateGroup method syntax has these parts.

Part

Description

group

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

object

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

name

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

pid

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


Remarks

You can use the CreateGroup method to create a new Group object for a User or Workspace. If you omit one or both of the optional parts when you use CreateGroup, 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 individual 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 Group object from a collection, use the Delete method on the Groups collection.

See Also

Append method, Delete method, Group object, Name property, PID property.

Specifics (Microsoft Access)

Once you have created a new Group object and appended it to the Groups collection of a Workspace or User object, you can verify that the new group exists by examining the Name list box on the Groups 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 CreateGroup method to create a new Group object; it then makes the "admin" user a member of the new Group object and lists its properties and users.

Sub CreateGroupX()

    Dim wrkDefault As Workspace
    Dim grpNew As Group
    Dim grpTemp As Group
    Dim prpLoop As Property
    Dim usrLoop As User

    Set wrkDefault = DBEngine.Workspaces(0)

    With wrkDefault

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

        ' Make the user "admin" a member of the
        ' group NewGroup by creating and adding the
        ' appropriate Group object to the user's Groups
        ' collection.
        Set grpTemp = .Users("admin").CreateGroup("NewGroup")
        .Users("admin").Groups.Append grpTemp

        Debug.Print "Properties of " & grpNew.Name

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

        Debug.Print "Users collection of " & grpNew.Name

        ' Enumerate the Users collection of NewGroup.
        For Each usrLoop In grpNew.Users
            Debug.Print "    " & _
                usrLoop.Name
        Next usrLoop

        ' Delete the new Group object because this
        ' is a demonstration.
        .Groups.Delete "NewGroup"

    End With

End Sub