How to open a the table window for the selected layer or standalone table in the table of contents in ArcMap. It provides the same functionality as the Open Attribute Table command on the layer context menu or the open command on the standalone table context menu (source).
Private SubUIButtonControl1_Click()DimpMxDocAsIMxDocumentDimpUnknownAsIUnknownDimpLayerAsILayerDimpStandaloneTableAsIStandaloneTableDimpTableWindow2AsITableWindow2DimpExistingTableWindowAsITableWindowDimSetPropertiesAs Boolean'Get the selected item from the current contents viewSetpMxDoc = ThisDocumentSetpTableWindow2 =NewTableWindowSetpUnknown = pMxDoc.SelectedItem' Determine the selected item's type' Exit sub if item is not a feature layer or standalone tableIf TypeOfpUnknownIsIFeatureLayerThen'A FeatureLayerSetpLayer = pUnknownSetpExistingTableWindow = _ pTableWindow2.FindViaLayer(pLayer)' Check if a table already exists; if not create oneIfpExistingTableWindowIs Nothing ThenpTableWindow2.Layer = pLayer SetProperties =
SetTruepUnknown
End If
ElseIf TypeOfIsIStandaloneTableThen' A standalone tableSetpStandaloneTable = pUnknownSetpExistingTableWindow = _ pTableWindow2.FindViaStandaloneTable(pStandaloneTable)' Check if a table already exists; if not, create oneIfpExistingTableWindowIs Nothing ThenpTableWindow2.StandaloneTable = pStandaloneTable SetProperties =
SetTrueSetProperties
End If
End If
IfThenpTableWindow2.TableSelectionAction = esriSelectFeatures pTableWindow2.ShowSelected =FalsepTableWindow2.ShowAliasNamesInColumnHeadings =TruepTableWindow2.Application = Application
SetElsepTableWindow2 = pExistingTableWindow
SetEnd If' Ensure Table Is VisibleIf NotpTableWindow2.IsVisibleThenpTableWindow2.ShowTrueUIButtonControl1_Enabled()
End Sub
Private FunctionAs BooleanpDoc
DimAsIMxDocumentDimpMapAsIMapDimbolEnabledAs BooleanpDoc = ThisDocument
SetSetpMap = pDoc.FocusMap bolEnabled =TruepSelItem
DimAsIUnknownSetpSelItem = pDoc.SelectedItem' Disable if the selected item is nothing or if' it is not a layer or tableIfpSelItemIs Nothing ThenbolEnabled =False(
ElseIf NotTypeOfpSelItemIsILayerOr TypeOfpSelItemIsIStandaloneTable)ThenbolEnabled =FalseUIButtonControl1_Enabled = bolEnabled
End IfEnd Function
Viewing Details: