CurrentObjectType, CurrentObjectName Properties Example
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, acSaveYes
End If
End If
End Sub