CurrentObjectType 属性

expandtri全部显示

可以使用 CurrentObjectType 属性和 Application 对象确定活动数据库对象的类型(表、查询、窗体、报表、宏、模块、数据访问页、服务器视图、数据库图表或存储过程)。活动数据库对象是获得了焦点的对象,或者其中的代码正在执行的对象。

CurrentObjectType 属性由 Microsoft Access 设置为以下 Microsoft Access 固有常量

设置

说明

acTable (0)

活动对象为表。

acQuery (1)

活动对象为查询。

acForm (2)

活动对象为窗体。

acReport (3)

活动对象为报表。

acMacro (4)

活动对象为宏。

acModule (5)

活动对象为模块。

acDataAccessPage (6)

活动对象为数据访问页。

acServerView (7)

活动对象为服务器视图

acDiagram (8)

活动对象为数据库图表。

acStoredProcedure (9)

活动对象为存储过程。

下列条件用于确定对象是否为活动对象:

?如果活动对象是对象的属性表、命令按钮、菜单、模板或属性列表CurrentObjectType 属性将返回基础对象的名称。

 

?如果活动对象是弹出式窗体CurrentObjectType 属性将引用弹出式窗体本身,而不是其下的窗体。

 

?如果活动对象是“数据库”窗口CurrentObjectType 属性将返回在“数据库”窗口中选取的对象。

 

?如果没有选取任何对象,CurrentObjectType 属性将返回 True

 

?如果当前状态比较模糊(活动对象不是表、查询、窗体、报表、宏或模块),如一个对话框获得焦点,则 CurrentObjectType 属性返回 True

可以将 SysCmd 方法与该属性一起使用来确定活动对象和它的状态(例如,对象是否打开、新建或是已经更改但还未保存)。

示例

以下示例使用 SysCmd 函数、CurrentObjectTypeCurrentObjectName 属性来确定活动对象是否为“产品”窗体,以及此窗体是否打开而且已经更改,只是没有保存。如果这些条件为真,则窗体将被保存然后关闭。

Public Sub CheckProducts()

    Dim intState As Integer

    Dim intCurrentType As Integer

    Dim strCurrentName As String

    intCurrentType = Application.CurrentObjectType

    strCurrentName = Application.CurrentObjectName

    If intCurrentType = acForm And strCurrentName = "Products" Then

        intState = SysCmd(acSysCmdGetObjectState, intCurrentType, _

                   strCurrentName)

        ' Products form changed but not saved.

        If intState = acObjStateDirty + acObjStateOpen Then

            ' Close Products form and save changes.

            DoCmd.Close intCurrentType, strCurrentName, acSaveYes

        End If

    End If

End Sub