Control 物件 (Access)Control object (Access)

Control 物件代表表單、報表或區段上、另一個控制項內或附加至另一個控制項的控制項。The Control object represents a control on a form, report, or section, within another control, or attached to another control.

註解Remarks

在表單或報表上的所有控制項都屬於Controls集合,該表單報表的物件。All controls on a form or report belong to the Controls collection for that Form or Report object. 在一個特別的區段內的控制項屬於該區段的 Controls 集合。Controls within a particular section belong to the Controls collection for that section. 在索引標籤控制項或選項群組控制項中的控制項屬於該控制項的 Controls 集合。Controls within a tab control or option group control belong to the Controls collection for that control. 附加至另一個控制項的標籤控制項屬於該控制項的 Controls 集合。A label control that is attached to another control belongs to the Controls collection for that control.

在參照 Controls 集合中個別的 Control 物件時,可以用隱喻或明確的方式參照 Controls 集合。When you refer to an individual Control object in the Controls collection, you can refer to the Controls collection either implicitly or explicitly.

' Implicitly refer to NewData control in Controls 
' collection. 
Me!NewData
' Use if control name contains space. 
Me![New Data]
' Performance slightly slower. 
Me("NewData")
' Refer to a control by its index in the controls 
' collection. 
Me(0)
' Refer to a NewData control by using the subform 
' Controls collection. 
Me.ctlSubForm.Controls!NewData
' Explicitly refer to the NewData control in the 
' Controls collection. 
Me.Controls!NewData
Me.Controls("NewData")
Me.Controls(0)

注意

您可以使用Me關鍵字來代表內的程式碼的表單報表物件,只有當您從在類別模組中的程式碼參照至表單或報表。You can use the Me keyword to represent a Form or Report object within code only if you are referring to the form or report from code within the class module. 如果您從標準模組或不同的表單或報表的模組參照至表單或報表,您必須使用完整的參照至表單或報表。If you are referring to a form or report from a standard module or a different form's or report's module, you must use the full reference to the form or report.

每一個 Control 物件是以一個特別的內部常數來表示。Each Control object is denoted by a particular intrinsic constant. 例如,acTextBox 內部常數代表文字方塊控制項,acCommandButton 內部常數代表指令按鈕。For example, the intrinsic constant acTextBox is associated with a text box control, and acCommandButton is associated with a command button. 針對不同的 Microsoft Access 控制項所宣告的常數會中所設定控制項的ControlType屬性。The constants for the various Microsoft Access controls are set forth in the control's ControlType property.

要決定一個存在的控制項類型,您可以使用 ControlType 屬性。To determine the type of an existing control, you can use the ControlType property. 不過,您不需要知道控制項,使用程式碼中的特定類型。However, you don't need to know the specific type of control to use it in code. 您可以簡單地使用資料類型為 Control 的變數來代表它。You can simply represent it with a variable of data type Control.

如果您的確知道您要參照哪一種控制項資料類型,而且該控制項是 Microsoft Access 的內建控制項,您應該以一個指定類型的變數來代表它。If you do know the data type of the control to which you are referring, and the control is a built-in Microsoft Access control, you should represent it with a variable of a specific type. 例如,如果您知道特別的控制項是一個文字方塊,請宣告 TextBox 類型的變數來代表它,如同下列的程式碼所顯示。For example, if you know that a particular control is a text box, declare a variable of type TextBox to represent it, as shown in the following code.

Dim txt As TextBox 
Set txt = Forms!Employees!LastName 

注意

如果控制項是 ActiveX 控制項,您必須宣告變數類型來代表; 它的控制項您無法使用特定的類型。If a control is an ActiveX control, you must declare a variable of type Control to represent it; you cannot use a specific type. 如果您不確定何種類型的變數會指向的控制項,將變數宣告為Control類型。If you are not certain what type of control a variable will point to, declare the variable as type Control.

選項群組控制項可以包含在其 Controls 集合內的其他控制項,包括選項按鈕、核取方塊、切換按鈕及標籤控制項。The option group control can contain other controls within its Controls collection, including option button, check box, toggle button, and label controls.

Tab 控制項包含 頁面 集合,這是一種特殊類型的 Controls 集合。The tab control contains a Pages collection, which is a special type of Controls collection. Pages集合包含**Page** 物件,也就是控制項。The Pages collection contains Page objects, which are controls. 在序列中的每個 Page 物件都包含一個 Controls 集合,此集合包含了該頁上所有的控制項。Each Page object in turn contains a Controls collection, which contains all of the controls on that page.

其他 控制項 物件必須可以含有附加的標籤 Controls 集合。Other Control objects have a Controls collection that can contain an attached label. 這些控制項包含文字] 方塊、 選項群組、 選項按鈕、 切換按鈕、 核取方塊、 下拉式方塊、 清單方塊、 命令按鈕、 結合的物件框及未結合的物件框控制項。These controls include the text box, option group, option button, toggle button, check box, combo box, list box, command button, bound object frame, and unbound object frame controls.

方法Methods

屬性Properties

請參閱See also

支援和意見反應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.