Sub MappingFields()
On Error GoTo EH:
'//initialize license
Dim aoi As IAoInitialize
Set aoi = New AoInitialize
aoi.Initialize esriLicenseProductCodeArcInfo
Dim GP As IGeoProcessor
Set GP = New GeoProcessor
GP.OverwriteOutput = True
Dim strTableA As String
strTableA = "C:"Temp"VBTests"FieldMapping"citiblocks.gdb"census"
Dim pDataElement As IDataElement
Dim pDETableA As IDETable
Dim pGPU As IGPUtilities
Set pGPU = New GPUtilities
Set pDataElement = pGPU.MakeDataElement(strTableA, Nothing, Nothing)
Set pDETableA = pDataElement
Dim pArray As IArray
Set pArray = New esriSystem.Array
pArray.Add pDETableA
Dim pFieldMapping As IGPFieldMapping
Set pFieldMapping = New GPFieldMapping
'** initialize the field mapping
pFieldMapping.Initialize pArray, Nothing
'** create a new output field
Dim TrackIDField As IFieldEdit
Set TrackIDField = New Field
TrackIDField.Name = "TRACTID"
TrackIDField.Type = esriFieldType.esriFieldTypeString
TrackIDField.Length = 20
'** create a new FieldMap
Dim TrackID As IGPFieldMap
Set TrackID = New GPFieldMap
Set TrackID.OutputField = TrackIDField
'** find field map STFID containing the input field STFID
Dim FieldMap_Index As Long, Field_Index As Long
FieldMap_Index = pFieldMapping.FindFieldMap("STFID")
Dim STFID_FieldMap As IGPFieldMap
Set STFID_FieldMap = pFieldMapping.GetFieldMap(FieldMap_Index)
Field_Index = STFID_FieldMap.FindInputField(pDETableA, "STFID")
Dim inputField As IField
Set inputField = STFID_FieldMap.GetField(Field_Index)
TrackID.AddInputField pDETableA, inputField, 5, 10 'starPos, endPos
'** add the new field map to the field mapping
pFieldMapping.AddFieldMap TrackID
'** execute Table to Table tool using the FieldMapping
Dim pParameters As IVariantArray
Set pParameters = New varArray
pParameters.Add (strTableA)
pParameters.Add ("C:"Temp"VBTests"FieldMapping"citiblocks.gdb")
pParameters.Add "census3"
pParameters.Add ""
pParameters.Add pFieldMapping
GP.Execute "TableToTable_conversion", pParameters, Nothing
Debug.Print GP.GetMessages(0)
Exit Sub
EH:
Debug.Print GP.GetMessages(2)
End Sub