Select By Attributes and Zoom to Selected Features

Discussion created by lauren_fagg on Oct 6, 2011
Latest reply on Oct 9, 2011 by lauren_fagg
hi all,

I'm just starting out in scripting and appreicate any help that I can get with this. I am trying to build a simple tool that will take text from two text boxes, enter them into an SQL query and hence select attributes from a "Cadastre - Parcels" Layer in my .mxd

The code I've written so far is this:

 Private Sub GoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoButton.Click

        Dim pMXDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
        pMXDoc = My.ArcMap.Document
        Dim pMap As ESRI.ArcGIS.Carto.IMap
        pMap = pMXDoc.FocusMap
        Dim pFeatureLayer As ESRI.ArcGIS.Carto.IFeatureLayer
        Dim pActiveView As ESRI.ArcGIS.Carto.IActiveView
        pActiveView = pMap
        Dim pFeatureSelection As ESRI.ArcGIS.Carto.IFeatureSelection
        Dim LayerName As String
        LayerName = "Cadastre - Parcels"

        For i = 0 To pMap.LayerCount - 1

            If UCase(pMap.Layer(i).Name.Trim()) = UCase(LayerName.Trim()) Then
                pFeatureLayer = pMap.Layer(i)
                Exit For
            End If

        'Get attributes from the textboxes
        Dim AttPlanNumber As String
        Dim AttLotNumber As String
        Dim SearchStatement As String

        AttPlanNumber = txtDPNumber.Text
        AttLotNumber = txtLotNumber.Text
        pFeatureSelection = pFeatureLayer

        Dim filter As New ESRI.ArcGIS.Geodatabase.QueryFilterClass()
        SearchStatement = "PLANNO = '" & AttPlanNumber & "' & LOTNO = '" & AttLotNumber & "'"
        filter.WhereClause = SearchStatement

        pActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

        pFeatureSelection.SelectFeatures(filter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, False)

End Sub

unfortunately, when I run the tool I get this:

pFeatureSelection.SelectFeatures(filter, ESRI.ArcGIS.Carto.esriSelectionResultEnum.esriSelectionResultNew, False) -----Check the ErrorCode property of the exception to determine the HRESULT returned by the COM Object.

Where am I going wrong?