Change Current Version in ArcMap

Created:3/26/2001
Description:

This sample provides two ways to change version in ArcMap: using a command button or programatically.

How to use:

    a.Change version using the command button

  1. Register the ChangeVersion.dll on your machine.
  2. Open an ArcMap document. The document needs to have a database connection with at least two versions to perform changing version.
  3. Choose Tools > Customize. Click on 'Add from file' and select ChangeVersion.dll.
  4. Under the Commands tab of the Customize dialog, select the 'Change Version (Sample)' command from the 'Samples' category, and drag it on to a toolbar. Dismiss the Customize dialog.
  5. Click the Source tab at the bottom of the table of contents to list the workspaces in your map. Select a workspace version.
  6. Click the 'Change Version' command added.
  7. Select the version to which you want to change in the tree view and click OK.

    b. Change version programmatically using the object ChangeVersionUtil

  1. Register the ChangeVersion.dll on your machine.
  2. Open an ArcMap document. The document needs to have a database connection with at least two versions to perform changing version.
  3. In the Visual Basic Editor, go to Tools > References. (If this sample's dll does not appear in the Available References box, Browse to the dll and add it.) Check the box next to the dll's name and dismiss the References dialog.
  4. To give an example of using the method of object ChangeVersionUtil, use the following procedure in VBA.
Sub ChangeVersionSample()
  On Error GoTo ErrorHandler
  Dim pMxDoc As IMxDocument
  Dim pVersion As IVersion
  Dim pFLyr As IFeatureLayer
  Dim pFClass As IFeatureClass
  Dim pDataset As IDataset
  Dim sCurrName As String
  Dim sToName As String
  Dim pChgVerUtil As ChangeVersion.ChangeVersionUtil
  Set pMxDoc = ThisDocument
  Set pFLyr = pMxDoc.FocusMap.Layer(0)
  Set pDataset = pFLyr.FeatureClass
  Set pVersion = pDataset.Workspace
  sCurrName = pVersion.VersionName
  Set pChgVerUtil = New ChangeVersion.ChangeVersionUtil
  sToName = InputBox("Please input the name of version", "Change Version")
  If (StrComp(sCurrName, sToName, vbTextCompare) = 0) Then
    MsgBox "Cannot change version - choose a version other than the current version"
    Exit Sub
  Else
    MsgBox "Current version: " & sCurrName
    pChgVerUtil.ChangeVersionByName pMxDoc, pVersion, sToName
    Set pFLyr = pMxDoc.FocusMap.Layer(0)
    Set pDataset = pFLyr.FeatureClass
    Set pVersion = pDataset.Workspace
    MsgBox "Version is changed to: " & pVersion.VersionName
  End If
  Exit Sub
ErrorHandler
   'simply exit 
End Sub
Application: ArcMap

Requires: A database connection having at least two versions

Difficulty: Intermediate


Visual Basic
File Description
ChangeVersionCmd.cls Implementation of ICommand for ChangeVersionCmd class.
ChangeVersionUtil.cls Provide utility functions to change version.
frmVersions.frm Providing a tree view of the versions of workspace
ChangeVersion.vbp Visual Basic Project file
ChangeVersion.dll The compiled DLL containing the implementation of the sample.


Key CoClasses: VersionedWorkspace
Key Interfaces: IVersion, IVersionedWorkspace, ICollectionTableVersionChanges, IMapAdmin2, IRelQueryTableManage
Key Members: IMapAdmin2::FireChangeVersion, IRelQueryTableManage::VersionChanged, ICollectionTableVersionChanges::Add