适用于
Form 对象 |
可以使用 AllowEdits 属性指定用户是否可以在使用窗体时编辑已保存的记录。 布尔型,可读/写。
表达式.AllowEdits
表达式 必需。 返回“适用范围”列表中的对象之一的表达式。
设置
AllowEdits 属性使用以下设置。
设置 |
Visual Basic |
说明 |
是 |
True |
(默认)用户可以编辑已保存的记录。 |
否 |
False |
用户不可以编辑已保存的记录。 |
可以通过使用窗体的属性表、宏或 Visual Basic for Applications (VBA) 代码来设置 AllowEdits 属性。
备注
可以使用 AllowEdits 属性,防止更改窗体显示的现有数据。 如果要防止更改特定控件中的数据,请使用 Enabled 或 Locked 属性。
如果想要防止更改现有记录(使窗体为只读),请将 AllowAdditions、AllowDeletions 和 AllowEdits 属性设置为“否”。 还可以将 RecordsetType 属性设置为“快照”,使记录为只读。
以编程方式更改字段值会使当前记录可编辑,而无需考虑 AllowEdits 属性设置。 如果要防止用户更改需要以编程方式编辑的记录(AllowEdits 为“否”),请在进行任何编程更改后保存记录;保存当前记录任何未保存的更改后,将再次执行 AllowEdits 属性设置。
注意: 设置 OpenForm 操作的 Data Mode 参数后,Microsoft Office Access 2007 将替代一些窗体属性设置。 如果 OpenForm 操作的“数据模式”参数设置为“编辑”,Access 将打开具有以下属性设置的窗体:
-
AllowEdits - 是
-
AllowDeletions - 是
-
AllowAdditions — 是
-
DataEntry — 否
若要防止 OpenForm 操作忽略这些现有属性设置中的任何一个,请省略“数据模式”参数设置,以便让 Access 使用窗体定义的属性设置。
示例
以下示例检查窗体上所有控件的 ControlType 属性。 对于每个标签和文本框控件,该过程将切换这些控件的 SpecialEffect 属性。 当标签控件的 SpecialEffect 属性设置为“阴影”、文本框控件的 SpecialEffect 属性设置为“平面”,且 AllowAdditions、AllowDeletions 和 AllowEdits 属性都设置为 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