Application.CurrentObjectType (Access)

You can use the CurrentObjectType property together with the Application object to determine the type of the active database object (table, query, form, report, macro, module, server view, database diagram, or stored procedure). The active database object is the object that has the focus or in which code is running. Here you can find possible values for AcObjectType.

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


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