Container, Permissions Properties Example (MDB)

The following example determines the name of the Container object to which a Document object belongs, and sets permissions accordingly for the specified group account. Remember that you must denote a particular user or group account before you set permissions for an object. The following example assumes that you have defined a Marketers group.

Microsoft Access defines additional Container objects beyond those defined by the Microsoft Jet database engine. These include the Form, Report, Script, and Module Container objects.

Note that the Or operator performs a bitwise comparison to determine whether an attribute is currently set.

Sub SetDocPermissions(docUnknown As Document)
    Dim strContainerName As String

    ' Set UserName property to valid existing group account.
    docUnknown.UserName = "Marketers"
    ' Get value of Container property.
    strContainerName = docUnknown.Container.Name
    Select Case strContainerName
        Case "Forms"
            ' Set permissions for Form Document object.
            docUnknown.Permissions = docUnknown.Permissions Or _
                acSecFrmRptWriteDef
        Case "Reports"
            ' Set permissions for Report Document object.
            docUnknown.Permissions = docUnknown.Permissions Or _
                acSecFrmRptExecute
        Case "Scripts"
            ' Set permissions for Script Document object.
            docUnknown.Permissions = docUnknown.Permissions Or _
                acSecMacWriteDef
        Case "Modules"
            ' Set permissions for Module Document object.
            docUnknown.Permissions = docUnknown.Permissions Or _
                acSecModReadDef
        Case Else
            Exit Sub
    End Select
End Sub