Access) (Form.AllowEdits 屬性

使用 AllowEdits 屬性來指定使用者在使用表單時是否可以編輯已儲存的記錄。 可讀寫的 Boolean。

語法

運算式。AllowEdits

expression 代表 Form 物件的變數。

註解

使用 AllowEdits 屬性來防止變更表單顯示的現有資料。 如果您想要為特定控制項中的資料以防止變更,使用 [ 已啟用 ] 或 [ 鎖定 ] 屬性。

若要防止變更現有的記錄 (使表單唯讀),設定 AllowAdditions 、 AllowDeletions 、 和 AllowEdits 屬性設為 no。 您也可以讓記錄唯讀 RecordsetType 屬性設定為快照。

AllowEdits 屬性設定為 [否時, 就有一個 刪除記錄 及 資料輸入 功能表命令不適用於現有的記錄。 (他們可能仍是可用的新記錄如果 AllowAdditions 屬性設定為 [是])。

以程式設計方式變更欄位值會造成目前記錄設為可編輯、 AllowEdits 屬性設定為何。 如果要防止使用者變更您需要以程式來編輯的記錄時 (AllowEdits 設定為 [否]),請在任何程式化變更後儲存記錄;對於目前記錄的未儲存變更,AllowEdits 屬性設定會再次套用。

注意事項

設定 OpenForm 巨集指令的 DataMode 引數時,Microsoft Access 會覆寫一些表單屬性設定。 如果 OpenForm 巨集指令的 DataMode 引數設為 [編輯],Access 會使用下列屬性設定開啟表單:

  • AllowEdits - 是
  • AllowDeletions - 是
  • AllowAdditions - 是
  • DataEntry - 否

若要防止 OpenForm 巨集指令覆寫任何現有的屬性設定,請省略 DataMode 引數設定,讓 Microsoft 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

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。