AllowEdits 属性

应用对象
Microsoft 365 专属 Access Access 2024 Access 2021 Access 2019 Access 2016

适用于

Form 对象

可以使用 AllowEdits 属性指定用户是否可以在使用窗体时编辑保存的记录。 布尔型,可读/写。

表达式.AllowEdits

表达 必填。 返回“适用范围”列表中的对象之一的表达式。

设置

AllowEdits 属性使用以下设置。

设置 Visual Basic 说明
True (默认)用户可以编辑已保存的记录。
False 用户不可以编辑已保存的记录。

      

可以使用窗体的属性表、宏或Visual Basic for Applications (VBA) 代码来设置 AllowEdits 属性。

备注

可以使用 AllowEdits 属性,防止更改窗体显示的现有数据。 如果要防止更改特定控件中的数据,请使用 EnabledLocked 属性。

如果想要防止更改现有记录(使窗体为只读),请将 AllowAdditionsAllowDeletionsAllowEdits 属性设置为“否”。 还可以将 RecordsetType 属性设置为“快照”,使记录为只读。

以编程方式更改字段值会使当前记录可编辑,而无需考虑 AllowEdits 属性设置。 如果要防止用户更改需要以编程方式编辑的记录(AllowEdits 为“”),请在进行任何编程更改后保存记录;保存当前记录任何未保存的更改后,将再次执行 AllowEdits 属性设置。

注意

设置 OpenForm 操作的数据模式参数后,Microsoft Office Access 2007 将替代许多表单属性设置。 如果 OpenForm 操作的“数据模式”参数设置为“编辑”,Access 将打开具有以下属性设置的窗体:

  • AllowEdits - 是
  • AllowDeletions - 是
  • AllowAdditions — 是
  • DataEntry — 否

若要防止 OpenForm 操作忽略这些现有属性设置中的任何一个,请省略“数据模式”参数设置,以便让 Access 使用窗体定义的属性设置。

示例

以下示例检查窗体上所有控件的 ControlType 属性。 对于每个标签和文本框控件,该过程将切换这些控件的 SpecialEffect 属性。 当标签控件的 SpecialEffect 属性设置为 Shadowed 且文本框控件的 SpecialEffect 属性设置为 Normal 并且 AllowAdditionsAllowDeletionsAllowEdits 属性都设置为 True 时, intCanEdit 该变量将切换为允许编辑基础数据。

Sub ToggleControl(frm As Form)
    Dim ctl As Control
    Dim intI As Integer, intCanEdit As Integer
    Const conTransparent = 0
    Const conWhite = 16777215
    For Each ctl in frm.Controls
        With ctl
            Select Case .ControlType
                Case acLabel
                    If .SpecialEffect = acEffectShadow Then
                        .SpecialEffect = acEffectNormal
                        .BorderStyle = conTransparent
                        intCanEdit = True
                    Else
                        .SpecialEffect = acEffectShadow
                        intCanEdit = False
                    End If
                Case acTextBox
                    If .SpecialEffect = acEffectNormal Then
                        .SpecialEffect = acEffectSunken
                        .BackColor = conWhite
                    Else
                        .SpecialEffect = acEffectNormal
                        .BackColor = frm.Detail.BackColor
                    End If
            End Select
        End With
    Next ctl
    If intCanEdit = IFalse Then
        With frm
            .AllowAdditions = False
            .AllowDeletions = False
            .AllowEdits = False
        End With
    Else
        With frm
            .AllowAdditions = True
            .AllowDeletions = True
            .AllowEdits = True
        End With
    End If
End Sub