ComboBox.ControlType 屬性 (Access)ComboBox.ControlType property (Access)

您可以使用 Visual Basic 中的ControlType屬性來判斷表單或報表上控制項的類型。You can use the ControlType property in Visual Basic to determine the type of control on a form or report. 可讀寫的 ByteRead/write Byte.

語法Syntax

運算式ControlTypeexpression.ControlType

_運算式_代表**ComboBox** 物件的變數。expression A variable that represents a ComboBox object.

註解Remarks

ControlType 屬性設定是會指定控制項類型的內部常數。The ControlType property setting is an intrinsic constant that specifies the control type. CreateControl 及**CreateReportControl** 方法所建立的控制項的完整清單,請參閱**AcControlType** 列舉型別。For a complete list of controls created by the CreateControl and CreateReportControl methods, see the AcControlType enumeration.

[!注意事項] ControlType 屬性僅可以使用 Visual Basic 中表單設計檢視或報表設計檢視設定,但是能在所有檢視中都讀取。The ControlType property can only be set by using Visual Basic in form Design view or report Design view, but it can be read in all views.

ControlType 屬性很有用檢查特定控制項類型的程式碼,但另一種類型來變更控制項的類型。The ControlType property is useful not only for checking for a specific control type in code, but also for changing the type of control to another type. 例如,您可以變更至下拉式方塊] 文字方塊中由文字方塊 ControlType 屬性設定為 acComboBox 在表單設計檢視中。For example, you can change a text box to a combo box by setting the ControlType property for the text box to acComboBox while in form Design view.

您可以使用 ControlType 屬性來變更類似根據特定條件表單上控制項的特性。You can use the ControlType property to change characteristics of similar controls on a form according to certain conditions. 例如,如果您不想要編輯現有的資料在文字方塊中的使用者,您可以所有文字方塊 SpecialEffect 屬性設定為普通並將該表單的 AllowEdits 屬性設定為 [否]。For example, if you don't want users to edit existing data in text boxes, you can set the SpecialEffect property for all text boxes to Flat and set the form's AllowEdits property to No. ( SpecialEffect 屬性不會影響是否可以編輯資料 ; 此處使用以提供視覺提示已變更的控制行為)。(The SpecialEffect property doesn't affect whether data can be edited; it's used here to provide a visual cue that the control behavior has changed.)

ControlType 屬性也用來指定要建立使用 CreateControl 方法時的控制項類型。The ControlType property is also used to specify the type of control to create when you are using the CreateControl method.

範例Example

下列範例會檢查 ControlType 屬性在表單上的所有控制項。The following example examines the ControlType property for all controls on a form. 每個標籤和文字] 方塊中控制項的程序會切換這些控制項的 SpecialEffect 屬性。For each label and text box control, the procedure toggles the SpecialEffect property for those controls.

當 [標籤] 控制項的SpecialEffect屬性設為陰影,並在文字方塊控制項的SpecialEffect屬性設為 Normal 和AllowAdditionsAllowDeletions、 和AllowEdits屬性全部設定為TrueintCanEdit變數就會切換為允許編輯的基礎資料。When the SpecialEffect property of the label control is set to Shadowed, and the SpecialEffect property of the text box control is set to Normal, and the AllowAdditions, AllowDeletions, and AllowEdits properties are all set to True, the intCanEdit variable is toggled to allow editing of the underlying data.

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

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.