Select to view content in your preferred language

Select Layer By Attribute

1479
1
12-22-2011 12:33 AM
StephenBell3
Emerging Contributor
Good morning everyone,

I am using geoprocessing within VBA (9.3 environment).  I am getting an automation error when trying to select attributes of a layer.  I have included code that I am trying.  Any thoughts?

Dim GP As Object
Set GP = CreateObject("esriGeoprocessing.GPDispatch.1")

GP.AddToolbox "C:/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx"

GP.AddToolbox "C:/ArcGIS/ArcToolbox/Toolboxes/Conversion Tools.tbx"


GP.OverwriteOutput = True


GP.MakeXYEventLayer_management "C:\File\Structure\tables\table.dbf", "Longitude", "Latitude", "Output_Layer", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];IsHighPrecision"

GP.FeatureClassToShapefile_conversion "Output_Layer", "C:\File\Structure"


GP.Project_management "C:\File\Structure\Output_Layer.shp", "C:\File\Structure\New_Output.shp", "PROJCS['British_National_Grid',GEOGCS['GCS_OSGB_1936',DATUM['D_OSGB_1936',SPHEROID['Airy_1830',6377563.396,299.3249646]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',400000.0],PARAMETER['False_Northing',-100000.0],PARAMETER['Central_Meridian',-2.0],PARAMETER['Scale_Factor',0.9996012717],PARAMETER['Latitude_Of_Origin',49.0],UNIT['Meter',1.0]]", "OSGB_1936_To_WGS_1984_Petroleum", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"


GP.SelectLayerByAttribute_management "C:\File\Structure\New_Output.shp", "NEW_SELECTION", "TYPE = 'W'"


The Feature Class To Shp was put in to try and solve the problem, but didn't, so I realise that might not need to exist.  The final shp is created but the selection is not run on it.

Many thanks in advance
Stephen
0 Kudos
1 Reply
BruceNielsen
Frequent Contributor
I think the only change you need to make is in your query statement:
GP.SelectLayerByAttribute_management "C:\File\Structure\New_Output.shp", "NEW_SELECTION", "\"TYPE\" = 'W'"

The column name for the selection needs to be enclosed in double quotes as well as the entire expression.

Lookup the article, "About building an SQL expression" in the desktop help.
0 Kudos