How To: Copy or load data and preserve GlobalID values with VBA

Summary

Instructions provided describe how to copy or load data and preserve GlobalID values with VBA. There are two approaches that can be used to do this using ArcObjects. The SDK article, How to copy or load data and preserve GlobalID values, has a more detailed discussion on this and includes .NET code. This article includes VBA versions of the code in that article.

Procedure

The VBA code below is an implementation of the two approaches described in the article referenced above. This code can be run from VBA in ArcCatalog. The code works on the selected feature class or table in ArcCatalog.

' Get the globalid field Dim classEX As IClassEx Dim pDSet As IDataset Set classEX = pTable If (Not classEX.HasGlobalID) Then Set pDSet = pTable MsgBox "No globalid field exists for table: " & pDSet.Name Exit Sub End If

' Get the GUID field to convert Dim fields As IFields Dim pDSet As IDataset Dim i As Integer Set fields = pTable.fields i = fields.FindField("globalid") If (i = -1) Then Set pDSet = pTable MsgBox "A field named globalid does not exist in table: " & pDSet.Name & _ ". If the field that you want to convert has another name, adjust the code and re-run it." Exit Sub End If

' make sure it is of type GUID Dim GUIDField As IField Set GUIDField = fields.Field(i) If (GUIDField.Type <> esriFieldTypeGUID) Then MsgBox "Field " & GUIDField.Name & " is not of type GUID" Exit Sub End If