Container Object, Containers Collection Example

The following example grants programmers full access to all modules in a database, and grants all other users read-only permissions on modules:

Sub SetModulePermissions()
    Dim dbs As Database, wsp As Workspace, ctr As Container
    Dim grp As Group

    ' Return reference to default workspace.
    Set wsp = DBEngine.Workspaces(0)
    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Return reference to Modules container.
    Set ctr = dbs.Containers!Modules
    wsp.Groups.Refresh
    For Each grp In wsp.Groups
        ctr.UserName = grp.Name
        If ctr.UserName = "Programmers" Then
            ctr.Permissions = ctr.Permissions Or dbSecFullAccess
        Else
            ctr.Permissions = ctr.Permissions Or acSecModReadDef
        End If
    Next grp
    Set dbs = Nothing
End Sub