全部显示

CurrentObjectName 属性

       

可以使用 CurrentObjectName 属性和 Application 对象确定活动数据库对象的名称。活动数据库对象是获得了焦点的对象,或者其中的代码正在执行的对象。String 型,只读。

expression.CurrentObjectName

expression   必需。返回“Applies To”列表中的一个对象的表达式。

说明

CurrentObjectName 属性由 Microsoft Access 设置为一个包含活动对象名称的字符串表达式

该属性仅在使用 Visual Basic 时才可用。

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

可以将 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