ComboBox.ControlType 属性 (Access)

使用 Visual Basic 中的 ControlType 属性确定窗体或报表上的控件类型。 可读/写 Byte 类型。

语法

表达式ControlType

表达 一个代表 ComboBox 对象的变量。

备注

ControlType 属性设置为指定的控件类型的固有常量。 有关 CreateControlCreateReportControl 方法创建的控件的完整列表,请参阅 AcControlType 枚举。

[!注释] 只能通过使用 Visual Basic 窗体设计视图或报表设计视图中,设置 ControlType 属性,但它可以在所有视图中读取。

ControlType 属性很有用不仅检查代码中的特定控件类型但也更改为其他类型的控件的类型。 例如,可以通过在文本框中将 ControlType 属性设置为在窗体设计视图中的 acComboBox 到组合框中更改文本框。

使用 ControlType 属性可以根据特定条件更改窗体上类似控件的特征。 例如,如果您不希望用户能够编辑文本框中的现有数据,可以将所有文本框的 特殊效果 属性设置为平面并将窗体的 允许编辑 属性设置为 no。 (是否可以编辑数据,并不会影响 特殊效果 属性; 它用于此处提供的视觉提示的控件行为已更改)。

ControlType 属性还用于指定要在使用 CreateControl 方法时创建的控件的类型。

示例

下面的示例检查在窗体上所有控件的 ControlType 属性。 对于每个标签和文本框控件,该过程切换为这些控件的 特殊效果 属性。

当标签控件的 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 支持和反馈,获取有关如何接收支持和提供反馈的指南。