Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
Access 2007
Application Object
Properties
 CurrentObjectName Property

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
Application.CurrentObjectName Property
You can use the CurrentObjectName property with the Application object to determine the name of the active database object. The active database object is the object that has the focus or in which code is running. Read-only String.

Syntax

expression.CurrentObjectName

expression   A variable that represents an Application object.

Remarks

The CurrentObjectName property is set by Microsoft Office Access 2007 to a string expression containing the name of the active object.

The following conditions determine which object is considered the active object:

  • If the active object is a property sheet, command bar, menu, palette, or field list of an object, the CurrentObjectName property returns the name of the underlying object.
  • If the active object is a pop-up form, the CurrentObjectName property refers to the pop-up form itself, not the form from which it was opened.
  • If the active object is the Database window, the CurrentObjectName property returns the item selected in the Database window.
  • If no object is selected, the CurrentObjectName property returns a zero-length string (" ").
  • If the current state is ambiguous (the active object isn't a table, query, form, report, macro, or module) for example, if a dialog box has the focus the CurrentObjectName property returns the dialog box name.

Example

You can use this property with the SysCmd method to determine the active object and its state (for example, if the object is open, new, or has been changed but not saved).

The following example uses the CurrentObjectType and CurrentObjectName properties with the SysCmd function to determine if the active object is the Products form and if this form is open and has been changed but not saved. If these conditions are true, the form is saved and then closed.

Visual Basic for Applications
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



Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker