Detect whether an object is open

It's often necessary to know whether a particular database object is open before you can edit the object programmatically. The following example illustrates how to use the SysCmd method with the acSysCmdGetObjectState action to determine whether a database object is open.

The example function, IsObjectLoaded, accepts two parameters. The strObjectName parameter is the name of the database object to check for. The strObjectType parameter is an AcObjectType constant that specifies the type of database object to check for. The IsObjectLoaded function returns True if the specified database object is open, and returns False if it is not open.

 
Function IsObjectLoaded(ByVal strObjectName As String, ByVal strObjectType As AcObjectType) As Boolean 
     
    If SysCmd(acSysCmdGetObjectState, strObjectType, strObjectName) <> 0 Then 
         
       ' The object is open. 
        IsObjectLoaded = True 
    Else 
 
       ' The object is not open. 
        IsObjectLoaded = False 
    End If 
     
End Function

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.