Geoprocessing Tool Failing in VBA Code

643
2
03-18-2013 12:49 PM
BruceNielsen
Occasional Contributor III
I have the code (VBA) below hooked up to a button in ArcMap 10.0. The first time it is used it runs successfully. If I try to run it a second time, the Intersect tool doesn't create the in_memory featureclass as expected and the code fails when it tries to run CalculateField. Any ideas as to why?

    (Identify and validate pLayer & pLayer2)
    ...
    'Intersect the PLU/soils data with the Sections
    Dim pGp As IGeoProcessor
    Set pGp = New GeoProcessor
    pGp.OverwriteOutput = True
    
    Dim pParams As IVariantArray
    Set pParams = New VarArray
    
    Dim PTS As String
    PTS = "PlanningToolSoils"
    
    pParams.RemoveAll
    pParams.Add pLayer.Name & "; " & pLayer2.Name
    pParams.Add "in_memory\" & PTS
    pParams.Add "NO_FID"
    pGp.Execute "Intersect_Analysis", pParams, Nothing
    
    'Update the CALCACRES Column
    pParams.RemoveAll
    pParams.Add PTS
    pParams.Add "CALCACRES"
    pParams.Add "!shape.area@acres!"
    pParams.Add "PYTHON"
    pGp.Execute "CalculateField_management", pParams, Nothing
    
    'Export the tabular portion of the FeatureClass to C:\temp\data.dbf
    pParams.RemoveAll
    pParams.Add PTS
    pParams.Add "C:\temp\Data.dbf"
    pGp.AddOutputsToMap = False
    pGp.Execute "CopyRows_management", pParams, Nothing
    
    'Delete the temporary featureclass
    pMap.DeleteLayer FindLayerByName(pMap, PTS) 'A home-built function that searches for an ILayer in the TOC 
    pParams.RemoveAll
    pParams.Add "in_memory\" & PTS
    pGp.Execute "Delete_management", pParams, Nothing
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Bruce,

Just thinking out aloud here. So on the second run of the code the intersect tool does not report any error and it does not create the in_memory dataset?

Are the layers changing, or are they the same layers but with a different selection on them? Also does one of the layers have the calcacres field?

Duncan
0 Kudos
BruceNielsen
Occasional Contributor III
Duncan,

Sorry I didn't respond sooner. I had kinda given up on getting any response from this thread.

You are correct. On the second run Intersect doesn't report an error. The source layers are always the same, and the CALCACRES field is always in one of the intersected layers.

Here's the odd thing I've found since the original post: If I run the code on another button between runs of this code, the second run of this code will complete.
0 Kudos