适用于
Form 对象 |
可以使用 AllowEdits 属性来指定用户是否可以在使用 窗体 时添加记录。 读取/写入布尔。
表达式.AllowAdditions
表达式 必需。 返回“适用范围”列表中的对象之一的表达式。
设置
AllowAdditions 属性使用以下设置。
设置 |
Visual Basic |
说明 |
是 |
True |
(默认)用户可添加新记录。 |
否 |
False |
用户无法添加新记录。 |
可以通过使用窗体的 属性表、宏 或 Visual Basic for Applications (VBA) 代码来设置 AllowAdditions 属性。
备注
将 AllowAdditions 属性设为“否”,可允许用户查看或编辑现有记录,但无法添加新记录。
如果想要防止更改现有记录(使窗体为只读),可将 AllowAdditions、AllowDeletions 和 AllowEdits 属性设置为“否”。 还可以通过将 RecordsetType 属性设置为“快照”,将记录设为只读。
如果打开窗体只是为了输入数据,可将窗体的 DataEntry 属性设置为“是”。
如果 AllowAdditions 属性设置为“否”,则“数据”选项卡上“记录”下的“新记录”命令不可用。
注意: 如果使用了 OpenForm 操作的“数据模式”参数,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