How to: Detect Whether an Object Is Open

Access Developer Reference

It is 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 databse 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 databse 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