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.
expression.CurrentObjectName
expression Required. An expression that returns one of the objects in the Applies To list.
This property is available only by using Visual Basic.
The following conditions determine which object is considered the active object:
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.
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