Inherit Property Example (MDB)

The following example sets the Inherit property of the Forms Container object to True (–1), and then sets the Permissions property to give users full security access to all forms. All new Document objects of the Form type will inherit these permissions. The procedure then creates a new Form object and displays the permissions for that object.

Note that the Forms Container object is different from the Forms collection. The Forms Container object includes all Form Document objects in the database; the Forms collection contains only currently open forms.

Also note that the Or operator performs a bitwise comparison to determine what permissions are currently set.

Sub FormPermissions()
    Dim dbs As Database, ctrForms As Container
    Dim docForm As Document, frmNew As Form

    ' Return reference to current database.
    Set dbs = CurrentDb
    ' Return reference to Forms container.
    Set ctrForms = dbs.Containers!Forms
    ' Set Inherit property.
    ctrForms.Inherit = True
    ' Set permissions to be inherited.
    ctrForms.Permissions = ctrForms.Permissions Or _
        acSecFrmRptWriteDef
    ' Create new form.
    Set frmNew = CreateForm()
    ' Save form.
    DoCmd.Save , "OrderForm"
    ' Return Document object associated with new form.
    Set docForm = ctrForms.Documents!OrderForm
    ' Compare permissions for Container and Document objects.
    If docForm.Permissions <> ctrForms.Permissions Then
        MsgBox "Error!"
    Else
        MsgBox "Permissions successfully inherited."
    End If
    Set dbs = Nothing
End Sub