CheckBox.ControlType 屬性 (Access)

使用 Visual Basic 中的 ControlType 屬性來判斷表單或報表上的控制項類型。 可讀寫的 Byte

語法

運算式ControlType

表達 代表 CheckBox 物件的變數。

註解

ControlType 屬性設定是會指定控制項類型的內部常數。 如需 CreateControlCreateReportControl 方法所建立之控制項的完整清單,請參閱 AcControlType 列舉。

[!注意事項] ControlType 屬性僅可以使用 Visual Basic 中表單設計檢視或報表設計檢視設定,但是能在所有檢視中都讀取。

ControlType 屬性很有用檢查特定控制項類型的程式碼,但另一種類型來變更控制項的類型。 例如,您可以變更至下拉式方塊] 文字方塊中由文字方塊 ControlType 屬性設定為 acComboBox 在表單設計檢視中。

使用 ControlType 屬性可根據特定條件變更表單上類似控制項的特性。 例如,如果您不想要編輯現有的資料在文字方塊中的使用者,您可以所有文字方塊 SpecialEffect 屬性設定為普通並將該表單的 AllowEdits 屬性設定為 [否]。 ( SpecialEffect 屬性不會影響是否可以編輯資料 ; 此處使用以提供視覺提示已變更的控制行為)。

ControlType 屬性也用來指定要建立使用 CreateControl 方法時的控制項類型。

範例

下列範例會檢查 ControlType 屬性在表單上的所有控制項。 每個標籤和文字] 方塊中控制項的程序會切換這些控制項的 SpecialEffect 屬性。

當標籤控制項的 SpecialEffect 屬性設定為 Shadowed,而且文字方塊控制項的 SpecialEffect 屬性設定為 Normal,而且 AllowAdditionsAllowDeletionsAllowEdits 屬性都設定為 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 支援與意見反應