テーブル結合を解除する方法

'How to remove all joins from a layer or table in ArcMap
'http://help.arcgis.com/en/sdk/10.0/vba_desktop/conceptualhelp/index.html#//000100000096000000

Public Sub RemoveAllJoins()
    
    On Error GoTo EH
    
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
    
    ' Get the selected layer or table
    Dim pSelItem As IUnknown
    Set pSelItem = pDoc.SelectedItem
    If pSelItem Is Nothing Then
        MsgBox "Nothing is selected in the table of contents"
        Exit Sub
    End If
    If Not (TypeOf pSelItem Is ILayer Or TypeOf pSelItem Is IStandaloneTable) Then
        MsgBox "A layer or table must be selected."
        Exit Sub
    End If
    
    Dim pDispRC As IDisplayRelationshipClass
    Set pDispRC = pSelItem
    
    ' Remove all joins
    If pDispRC.RelationshipClass Is Nothing Then
        MsgBox "The layer or table is not joined."
        Exit Sub
    End If
    
    pDispRC.DisplayRelationshipClass Nothing, esriLeftInnerJoin
    
    Exit Sub
EH:
    
    MsgBox Err.Number & "  " & Err.Description
    


'http://edndoc.esri.com/arcobjects/9.0/Samples/Tables/Remove_the_last_join_from_a_layer_or_table_in_ArcMap.htm
'How to remove the last join from a layer or table in ArcMap
Public Sub RemoveLastJoin()
    
    ' Get the map
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pMap As IMap
    Set pMap = pDoc.FocusMap
    
    ' Get the selected layer or table
    Dim pSelItem As IUnknown
    Set pSelItem = pDoc.SelectedItem
    If Not TypeOf pSelItem Is IDisplayTable Then
        MsgBox "No Feature layer or table selected"
        Exit Sub
    End If
    
    ' Make sure the selected layer is joined
    Dim pDispTable As IDisplayTable
    Dim pTable As ITable
    Set pDispTable = pSelItem
    Set pTable = pDispTable.DisplayTable
    If Not TypeOf pTable Is IRelQueryTable Then
        MsgBox "The layer or table is not joined"
        Exit Sub
    End If
    
    ' Get the source table of the current join
    ' object (RelQueryTable)
    Dim pRelQTab As IRelQueryTable
    Set pRelQTab = pTable
    Set pTable = pRelQTab.SourceTable
    
    ' UnJoin
    Dim pDispRC As IDisplayRelationshipClass
    Dim pRQTInfo As IRelQueryTableInfo
    Set pDispRC = pSelItem
    ' If more than one table had been joined, replace
    ' the current join with the previous join
    If TypeOf pTable Is IRelQueryTable Then
        Set pRelQTab = pTable
        Set pRQTInfo = pRelQTab
        pDispRC.DisplayRelationshipClass pRelQTab.RelationshipClass, pRQTInfo.JoinType
        ' If one table has been joined, remove all joins
    Else
        pDispRC.DisplayRelationshipClass Nothing, esriLeftInnerJoin
    End If
    
End Sub