Important : Selected shapefile features using postfix Clauses (Order By).

423
1
09-04-2012 11:07 PM
Highlighted
New Contributor
Hi All,
I want to select the shapefile features using ORDER BY clause, but could not find the solution.
I getting the error : "Object Variable or With block variable is not SET". (at this line : Set pFeatureCursor = pFeatureClass.Search(pQueryFilter, False)).

Seeking your urgent help, if anybody knows the solutions pl help me to resolve this issue.

Here is my full code :

Public Sub SelectMapFeatures()
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Dim pActiveView As IActiveView
  Dim pFeatureLayer As IFeatureLayer
  Dim pFeatureSelection As IFeatureSelection
  Dim pQueryFilter As IQueryFilter
  Dim pQueryFilterDefinition As IQueryFilterDefinition

  Set pQueryFilterDefinition = pQueryFilter
  Set pMxDoc = Application.Document
  Set pMap = pMxDoc.FocusMap
  Set pActiveView = pMap

  'For simplicity sake let's use the first layer in the map
  If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub
  Set pFeatureLayer = pMap.Layer(0)
  Set pFeatureSelection = pFeatureLayer 'QI

  'Create the query filter
  Set pQueryFilter = New QueryFilter
  pQueryFilter.SubFields = "STATE_NAME,Shape,FID"

  pQueryFilter.WhereClause = "FID> 10"

  pQueryFilterDefinition.PostfixClause = "ORDER BY STATE_NAME"

  Dim pFeatureCursor As IFeatureCursor
  Dim pFeatureClass As IFeatureClass
  Set pFeatureCursor = pFeatureClass.Search(pQueryFilter, False)

  ' Set pCursor = pQueryFilterDefinition.Search(pQueryFilter, False)
  'Invalidate only the selection cache
  'Flag the original selection
  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
  'Perform the selection
  pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
  'Flag the new selection
  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing

End Sub


Seeking your urgent help, if anybody knows the solutions pl help me to resolve this issue.
0 Kudos
1 Reply
Highlighted
Regular Contributor III
You haven't set pFeatureClass to anything.  You have to set it to something before you can use it.
0 Kudos