Form.AllowEdits 属性 (Access)
使用 AllowEdits 属性指定用户是否可以在使用窗体时编辑保存的记录。 读/写 Boolean。
语法
表达式。AllowEdits
expression:表示 Form 对象的变量。
备注
使用 AllowEdits 属性可防止更改窗体显示的现有数据。 如果要阻止特定控件中的数据更改,使用 启用 或 锁定 属性。
如果希望防止更改现有记录 (使窗体成为只读的), 允许添加 、 允许删除 ,和 允许编辑 属性设置为 no。 通过 记录集类型 属性设置为快照,还可以进行只读记录。
当 AllowEdits 属性设置为“否”时, “删除记录 ”和“ 数据输入 ”菜单命令不适用于现有记录。 (如果 AllowAdditions 属性设置为“是”,则它们可能仍可用于新记录。)
以编程方式更改字段值将导致当前记录可以进行编辑,而不考虑 允许编辑 属性设置。 如果要防止用户对需要通过编程才能编辑的记录(AllowEdits 为“否”)进行更改,请在以编程方式进行所有更改后保存该记录;保存了对当前记录所有未保存的更改后,AllowEdits 属性设置将重新生效。
注意
设置 OpenForm 操作的 DataMode 参数后,Microsoft Access 将替代许多表单属性设置。 如果 OpenForm 操作的 DataMode 参数设置为“编辑”,Access 将使用以下属性设置打开窗体:
- AllowEdits - 是
- AllowDeletions - 是
- AllowAdditions - 是
- DataEntry - 否
若要防止 OpenForm 操作重写这些现有属性设置中的任何一个,请省略 DataMode 参数设置,以便 Microsoft Access 将使用窗体定义的属性设置。
示例
下面的示例检查在窗体上所有控件的 ControlType 属性。 对于每个标签和文本框控件,该过程切换为这些控件的 特殊效果 属性。 当标签控件的 SpecialEffect 属性设置为 Shadowed 时,文本框控件的 SpecialEffect 属性设置为 Normal,并且 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
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。