Report.ActiveControl 属性 (Access)

ActiveControl 属性与 Screen 对象一起使用,以标识或引用具有焦点的控件。 只读的 控件 对象。

语法

表达式ActiveControl

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

备注

该属性设置包含对在运行时具有焦点的 控件 对象的引用。

使用 ActiveControl 属性可引用在运行时具有焦点的控件及其属性或方法之一。 下面的示例对 strControlName变量赋以具有焦点的控件的名称。

Dim ctlCurrentControl As Control 
Dim strControlName As String 
Set ctlCurrentControl = Screen.ActiveControl 
strControlName = ctlCurrentControl.Name

如果没有控件具有焦点,当您使用 ActiveControl 属性,或者隐藏或禁用的所有活动窗体的控件,将发生错误。

示例

以下示例将活动控件分配给 ctlCurrentControl 变量,然后根据控件的 Name 属性的值采取不同的操作。

Dim ctlCurrentControl As Control 
 
Set ctlCurrentControl = Screen.ActiveControl 
If ctlCurrentControl.Name = "txtCustomerID" Then 
 . 
 . ' Do something here. 
 . 
ElseIf ctlCurrentControl.Name = "btnCustomerDetails" Then 
 . 
 . ' Do something here. 
 . 
End If

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。