HOW TO

Programmatically get the current version from an SDE layer

Last Published: April 25, 2020

Summary

This article shows how to get the version name for the first layer in ArcMap.

Procedure



  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. In the Project Explorer window, expand Project.mxt and select ArcMap Objects > ThisDocument. Right-click and select View Code.
    [O-Image] Visual Basic Project  Explorer
    Note:
    Code in ThisDocument module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.

  4. Copy the following into the code module.

    Code:
    Sub GetVersion()
    'Returns the version for the
    'first layer in ArcMap
    Dim pDoc As IMxDocument
    Set pDoc = ThisDocument
    Dim pLayer As IFeatureLayer
    Set pLayer = pDoc.FocusMap.Layer(0)
    Dim pDataset As IDataset
    Set pDataset = pLayer.FeatureClass
    Dim pVersion As IVersion
    Set pVersion = pDataset.Workspace
    MsgBox pVersion.VersionName
    End Sub

  5. Close the Visual Basic Editor.
  6. Run the code.

    A. Click Tools > Macros > Macros to display the Macros dialog box.
    B. Select a macro and click Run.

Article ID:000004953

Software:
  • ArcMap 8 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic