使用 AllowAdditions 屬性可以指定用戶是否可在使用窗體時添加記錄。Boolean 型,可讀寫。
expression.AllowAdditions
expression 必需。返回“應用于”列表中的一個對象的表達式。
AllowAdditions 屬性使用以下設置:
設置 |
Visual Basic |
說明 |
是 |
True |
(默認值)用戶可以添加記錄。 |
否 |
False |
用戶不能添加記錄。 |
可以使用窗體屬性表、宏或 Visual Basic 來設置 AllowAdditions 屬性。
AllowAdditions 屬性設置為“否”時,用戶可以查看或編輯已有的記錄,但不能添加記錄。
如果要禁止更改已有記錄(使窗體只讀),可以將 AllowAdditions、AllowDeletions 和 AllowEdits 屬性設置為“否”。也可以將 RecordsetType 屬性設置為“快照”,使記錄成為只讀。
如果打開窗體只是為了輸入數(shù)據(jù),可以將窗體的 DataEntry 屬性設置為“是”。
當 AllowAdditions 屬性設置為“否”時,“記錄”菜單上的“數(shù)據(jù)輸入”命令將失效。
注釋 當使用 OpenForm 操作的“數(shù)據(jù)模式”參數(shù)時,Microsoft Access 將忽略許多窗體屬性設置。如果 OpenForm 操作的“數(shù)據(jù)模式”參數(shù)設置為“編輯”,Microsoft Access 所打開的窗體將具有以下屬性設置:
? | AllowEdits:是 |
? | AllowDeletions:是 |
? | AllowAdditions:是 |
? | DataEntry:否 |
要防止 OpenForm 操作忽略任何現(xiàn)有的屬性設置,可以省略“數(shù)據(jù)模式”參數(shù),使 Microsoft Access 使用窗體定義的屬性設置。
下面的示例檢查窗體上所有控件的 ControlType 屬性,并切換每個標簽控件和文本框控件的 SpecialEffect 屬性。當標簽控件的 SpecialEffect 屬性設置為“陰影”,文本框控件的 SpecialEffect 屬性設置為“常規(guī)”,AllowAdditions、AllowDeletions 和 AllowEdits 屬性設置為 True 時,intCanEdit 變量將切換到允許編輯基礎數(shù)據(jù)的狀態(tài)。
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