CurrentObjectName 屬性

此頁沒有內容條目
內容

expandtri全部顯示

可以使用 CurrentObjectName 屬性和 Application 對象確定活動數(shù)據(jù)庫對象的名稱。活動數(shù)據(jù)庫對象是獲得了焦點的對象,或者其中的代碼正在執(zhí)行的對象。String 型,只讀。

expression.CurrentObjectName

expression     必需。返回“應用于”列表中的一個對象的表達式。

說明

CurrentObjectName 屬性由 Microsoft Access 設置為一個包含活動對象名稱的字符串表達式

該屬性僅在使用 Visual Basic 時才可用。

下列條件用于確定對象是否為活動對象:

?如果活動對象是對象的屬性表、命令按鈕、菜單、模板或屬性列表,CurrentObjectName 屬性將返回基礎對象的名稱。
?如果活動對象是彈出式窗體,CurrentObjectName 屬性將引用彈出式窗體本身,而不是其下的窗體。
?如果活動對象是“數(shù)據(jù)庫”窗口,CurrentObjectName 屬性將返回在“數(shù)據(jù)庫”窗口中選取的對象。
?如果沒有選取任何對象,CurrentObjectName 屬性將返回零長度字符串 (" ")。
?如果當前狀態(tài)比較模糊(活動對象不是表、查詢、窗體、報表、宏或模塊),如一個對話框獲得焦點,則 CurrentObjectName 屬性返回對話框的名稱。

可以將 SysCmd 方法與該屬性一起使用,來確定活動對象和它的狀態(tài)(例如,對象是否打開、新建或是已經(jīng)更改但還未保存)。

示例

以下示例使用 SysCmd 函數(shù)、CurrentObjectTypeCurrentObjectName 屬性來確定活動對象是否為“產(chǎn)品”窗體,以及此窗體是否打開而且已經(jīng)更改,只是沒有保存。如果這些條件為真,則窗體將被保存然后關閉。

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