Query with String Variable

Discussion created by flederfauz on May 16, 2010
Latest reply on May 17, 2010 by flederfauz

I want to query a feature with a variable in string format. I read plenty of postings related to this issue but none of the solutions worked for mer. Hope somebody can help me on this.

Private Sub UpdateValue()

' Par 1: Define the feature class.
Dim pMxDoc As IMxDocument
Dim pFeatLayer As IFeatureLayer
Dim pFeatureClass As IFeatureClass
Dim pFields As IFields
Dim ii As Integer
Dim p As String
Set pMxDoc = ThisDocument
Set pFeatLayer = pMxDoc.FocusMap.Layer(0)
Set pFeatureClass = pFeatLayer.FeatureClass
p = A1

' Part 2: Prepare a feature cursor.
Dim pQFilter As IQueryFilter
Dim pUpdateFeatures As IFeatureCursor
' Prepare a query filter.
Set pQFilter = New QueryFilter
  pQFilter.WhereClause = "To_='" & p & "'"

' Create a feature cursor for updating.
Set pUpdateFeatures = pFeatureClass.Update(pQFilter, False)

' Part 3: Calcuate the Class value.
Dim indexClass As Integer
Dim pFeature As IFeature
indexClass = pUpdateFeatures.FindField("Amount")
Set pFeature = pUpdateFeatures.NextFeature
' Loop through each feature and update its Class value.
Do Until pFeature Is Nothing
pFeature.Value(indexClass) = 1
pUpdateFeatures.UpdateFeature pFeature
Set pFeature = pUpdateFeatures.NextFeature

End Sub

If I write instead of  pQFilter.WhereClause = "To_='" & p & "'" pQFilter.WhereClause"To_='A1' " everything works find. But i need to use the variable as i have to develop the code further. I also tried "To_='" & p & "'" and many other combinations.

any idea where the mistake might be or how i can work around?

Best regards