適用對象
Form 物件 |
您可以使用 AllowAdditions 屬性來指定使用者是否可以在使用表單時新增記錄。 讀/寫布林值。
運算式.AllowAdditions
運算式 必要。 傳回 [套用至] 清單中其中一個對象的表達式。
設定
AllowAdditions 屬性使用下列設定。
設定 |
Visual Basic |
描述 |
---|---|---|
Yes |
True |
(預設) 使用者可以新增記錄。 |
No |
False |
使用者無法新增記錄。 |
您可以使用表單的屬性工作表、巨集或 Visual Basic for Applications (VBA) 程式碼來設定 AllowAdditions 屬性。
備註
將 AllowAdditions 屬性設為No 可允許使用者檢視或編輯現有記錄,但不允許新增記錄。
如果您想要防止對現有記錄進行變更 (讓表單變成唯讀狀態),請將 AllowAdditions、AllowDeletions 和 AllowEdits 屬性設為 No。 您也可以將 RecordsetType 屬性設為 Snapshot,讓記錄變成唯讀狀態。
如果您僅為輸入資料而開啟表單,請將表單的 DataEntry 屬性設為 Yes。
當 AllowAdditions 屬性設為 No 時,則無法使用 [資料] 索引標籤的 [記錄] 底下的 [新增記錄] 命令。
附註: 使用 OpenForm 宏指令的 Data Mode 自變數時,Access 會覆寫數個窗體屬性設定。 如果 OpenForm 動作的 Data Mode 引數設為 Edit,Access 將會開啟具有下列屬性設定的表單:
-
AllowEdits — 是
-
AllowDeletions — 是
-
AllowAdditions — 是
-
DataEntry — 否
若要防止 OpenForm 動作覆寫任何現有的屬性設定,請忽略 Data Mode 引數設定,讓 Access 使用表單定義的屬性設定。
範例
下列範例會在表單上檢查所有控制項的 ControlType 屬性。 對於每個標籤和文字方塊控制項,此程序可以切換這些控制項的 SpecialEffect 屬性。 當標籤控制項的 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