Select to view content in your preferred language

Query Attribute Table with VBA

671
1
06-08-2010 12:07 PM
TrevorRobertson
New Contributor
I'm creating a form that will automatically update the zoning layer. I need help with the first part.
I need the user to input the Address into a text box then search the feature class for that address.
With that address I need to populate some labels with information in the same table as the address, like zoning.

I've searched for hours and couldn't really come up with anything worht while I don't think

Private Sub cmdsearch_Click()
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Dim pActiveView As IActiveView
  Dim pFeatureLayer As IFeatureLayer
  Dim pFeatureSelection As IFeatureSelection
  Dim pQueryFilter As IQueryFilter
  
  Set pMxDoc = Application.Document
  Set pMap = pMxDoc.FocusMap
  Set pActiveView = pMap
  
  
  If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub
  Set pFeatureLayer = pMap.Layer(0)
  Set pFeatureSelection = pFeatureLayer 'QI
  
  Dim DEMname
  DEMname = Me.TxtAddress.Text
  
  Set pQueryFilter = New queryFilter
  pQueryFilter.whereClause = "ADDRESS = 'DEMname'"
  

  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
  pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
  
End Sub
0 Kudos
1 Reply
JamesMacKay
Deactivated User
One problem is that you're using a variable as a literal. You need to concatenate the literal parts of the string with the variable like this:

pQueryFilter.whereClause = "ADDRESS = '" & DEMname & "'"
0 Kudos