Select the SDE connection (source tab) of a layer in arcmap (9.3.1)

Discussion created by johnnhansen on Apr 16, 2010
Latest reply on Jul 10, 2010 by aramsdell
(previously posted in another forum - these new ones will take some time...)

Been banging my head on this one for too long. Would like to know how to programmatically (preferably vba) select (highlight) an SDE Connection in the source tab (see attached image). The mxd is for editing versioned sde data, and the user will be changing versions regularly, but the layers in the map will remain static. Thus, I know that the layer 'PageIndex' will always be in the map, but it's source (SDE Version) will always be different. I am sure that arcmap knows what the source of that layer is, I just can't seem to figure out how to expose that information (and then select it).

Here is my latest (feable) attempt at this - any help would be appreciated:

Sub SelectVersion_old()
'not working

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim i As Integer
Dim LayerName As String
Dim pTOC As IContentsView
Dim workspaceFactory As IWorkspaceFactory
Dim pDocDataset As IDocumentDatasets
Dim pDataset As IDataset
Dim pDSName As IDatasetName
Dim pFeatureLayer As IFeatureLayer
Dim pVersion As IVersion
Dim pWorkspace As IWorkspace

' Set a reference to the current map document
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pTOC = pMxDoc.CurrentContentsView
Set workspaceFactory = New SdeWorkspaceFactory
'sDatasetName = pDataset.Name

LayerName = "PageIndex"

' Determine the position or order of the Layer in the TOC
For i = 0 To pMap.LayerCount - 1
If UCase(pMap.Layer(i).Name) = UCase(LayerName) Then
' Make the layer active (like you selected it)
'pTOC.SelectedItem = pMap.Layer(i)
Set pDataset = pMap.Layer(i)
'Set pDSName = pDataset.Name
Set pWorkspace = pDataset.workspace

'Set pWorkspace = workspaceFactory
'pTOC.SelectedItem = pWorkspace
'Set pDataset = pFeatureLayer.FeatureClass
'Set pVersion = pWorkspace
'Set pMap.SelectedItem = pWorkspace
'MsgBox "Version: " & pVersion.VersionName
End If
Next i

' Refresh the table of contents (TOC)
End Sub