Application Object.
You can use the CurrentObjectType and CurrentObjectName properties together with the Application object to determine the type of the active database object (table, query, form, report, macro, or module) and the name of the active database object.
The CurrentObjectType property is set by Microsoft Access to one of the following Microsoft Access intrinsic constants.
Setting | Description |
acTable | The active object is a table. |
acQuery | The active object is a query. |
acForm | The active object is a form. |
acReport | The active object is a report. |
acMacro | The active object is a macro. |
acModule | The active object is a module. |
The CurrentObjectName property is set by Microsoft Access to a string expression containing the name of the active object.
These property settings are available only in Visual Basic and are read-only in all views.
The following conditions determine which object is considered the active object:
You can use these properties with the SysCmd function to determine the active object and its state (for example, if the object is open, new, or has been changed but not saved).
Application Object, SysCmd Function.
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.
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, acYes End If End IfSub