Creating and Deleting Groups

Rather than assign access permissions to individual users, as mentioned above, you can create Groups to which one or more users can be assigned. Each Group can be assigned specific permissions to the database's objects, and every user who is assigned to that group will inherit the permissions of that Group. As we'll examine in this section, using DAO, you can create or delete Groups in code. The following code shows how to create a new group. The basic procedure is to create the group using the CreateGroup method, and then append it to the Groups collection.

Public Sub CreateUserGroup(strGroupName As String, _ strPID As String) Dim wrk As DAO.Workspace Dim grp As DAO.Group

Set wrk = DBEngine(0)

On Error GoTo CreateUserGroupErr

'Create the new group

Set grp = wrk.CreateGroup(strGroupName, strPID) ws.Groups.Append grp

CreateUserGroupErr: Set grp = Nothing Set wrk = Nothing End Sub

Deleting a group is even easier; just execute the Groups collection's Delete method.

Public Sub DeleteGroup(strGroup As String) On Error Resume Next DBEngine(0).Groups.Delete strGroup End Sub

You can't rename a group once it has been created. If you need to rename a group, you have to delete it, and then re-create it. Remember, though, if you need to re-create a user or group, you must supply the same SID that you used to create it in the first place.

Was this article helpful?

0 0

Post a comment