Open Attribute Table of a Standalone Table

3896
4
06-29-2010 10:09 AM
CK
by
New Contributor
Hi everyone!

I have a ComboBox with all names of the Feature Layers that are listed in the Table of Contents. Furthermore, the ComboBox includes some Standalone Tables. What I want is to open the attribute table of the layer or standalone table which has been selected in the ComboBox. I know the code for feature layers but not for standalone tables. Can anybody help please?

Here is the code to open the attribute table of a feature layer:

    Dim pMxDocument      As IMxDocument
    Dim pLayer                As ILayer
    Dim pUID                  As New UID
    Dim pCommandItem    As ICommandItem
   
    Dim strLayername As String
    strLayername = ComboBox.value
   
    Set pMxDocument = ThisDocument
    Set pLayer = general.FindLayer(strLayername)
    pMxDocument.ContextItem = pLayer

    pUID.value = "esriArcMapUI.FeatureLayerContextMenuItems"
    pUID.SubType = 4
    Set pCommandItem = Application.Document.CommandBars.Find(pUID)
    pCommandItem.Execute
0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
Hello,

Sample code can be found in the Developers Help. It is under VBA Samples>Tables>Open a Table window.

Duncan
0 Kudos
CK
by
New Contributor
Hi Duncan!
This works fine. Thank you so much. 🙂 My problem is that in this sample you have to select a layer in the TOC and not in a combobox. Unfortunately, I don't know how to find out if the layer behind the selected name is a feature layer, a dBASE table or an excel table. Do you have any idea?
0 Kudos
TerryGiles
Occasional Contributor III
How did you get the names of the layers and tables into the combobox?  Probably by some simple looping through IMap:Layers & IStandaloneTableCollection.  You can do the same to find the selected item in the combobox.  Code below might not be 100% correct as I'm just typing & haven't tried it.

for intX = 0 to pMap.layercount -1
  if pmap.layer(intx).name = combobox1.value then
    'call modified dev sample
    OpenWindow(pmap.layer(intx))
    exit sub 
 end if
next
'if not a layer try the tables
dim pSTColl as iStandaloneTableCollection
set pstcoll = pmap
for intx = 0 to pstcoll.StandaloneTableCount -1
  if pstcoll.standaloneTable(intx).name = combobox1.value then
    openWindow(pstcoll.standaloneTable(intx))
    exit sub
 endif

next

'if could not find either a layer or table...
msgbox("couldn't find it")
exit sub

'modified vba sample from Dev Help
Private Sub OpenWindow(pUnknown as IUnknown)
  Dim pMxDoc As IMxDocument

  Dim pLayer As ILayer
  Dim pStandaloneTable As IStandaloneTable
  Dim pTableWindow2 As ITableWindow2
  Dim pExistingTableWindow As ITableWindow
  Dim SetProperties As Boolean
  
  'Get the selected item from the current contents view
  Set pMxDoc = ThisDocument
  Set pTableWindow2 = New TableWindow

  
  ' Determine the selected item's type
  ' Exit sub if item is not a feature layer or standalone table
  If TypeOf pUnknown Is IFeatureLayer Then 'A FeatureLayer
    Set pLayer = pUnknown
    Set pExistingTableWindow = _
    pTableWindow2.FindViaLayer(pLayer)
    ' Check if a table already exists; if not create one
    If pExistingTableWindow Is Nothing Then
      Set pTableWindow2.Layer = pLayer
      SetProperties = True
    End If
  ElseIf TypeOf pUnknown Is IStandaloneTable Then
    ' A standalone table
    Set pStandaloneTable = pUnknown
    Set pExistingTableWindow = _
    pTableWindow2.FindViaStandaloneTable(pStandaloneTable)
    ' Check if a table already exists; if not, create one
    If pExistingTableWindow Is Nothing Then
      Set pTableWindow2.StandaloneTable = pStandaloneTable
      SetProperties = True
    End If
  End If
  
  If SetProperties Then
    pTableWindow2.TableSelectionAction = esriSelectFeatures
    pTableWindow2.ShowSelected = False
    pTableWindow2.ShowAliasNamesInColumnHeadings = True
    Set pTableWindow2.Application = Application
  Else
    Set pTableWindow2 = pExistingTableWindow
  End If
  
  ' Ensure Table Is Visible
  If Not pTableWindow2.IsVisible Then pTableWindow2.Show True
  
End Sub





hope this helps, TG
0 Kudos
CK
by
New Contributor
Thank you so much! This is exactly what I was searching for. 🙂
0 Kudos