Environment: Visual Basic Editor
Language: VB6
I posted earlier on this, and got some great replies, but I didn't do a good job of explaining what I'm working on. This time, I have some code samples, and even a picture - I'm prepared.
At my company we produce map books - lots of them. Our boss decided he wanted a really pretty table for the layout, so he had someone design it in Excel. Then our GIS folks had to hand enter the data into the spreadsheet, and copy and paste it into ArcMap. Not so much fun (especially when the map book is 50+ pages). So my boss asks me, "Hey, is there any way we could automatically populate that table instead of having to pay people $40/hr to do data entry?" My first thought is, "No, boss. It's a pasted version of an Excel spreadsheet. I can't get to it." Wanting to keep my job, however, I respond, "Sure! I'll figure something out!" So I did.
If you open up the attachment, you'll see a picture of the table we use. The goal is to populate an entire row of the table when the user selects one of the features using the combo box on the right (you'll notice there are three combo boxes - one for each row). Right now, I've got the combo boxes and the header row populating on the OpenDocument event, and the first cell of each row populating on the SelectionChange event of the combo box. Now I've got to get the rest of the row to populate. My current code is below. My problem is that when I make a selection, the code snags at:
Set pFCursor = pFClass.Search(pQueryFilter, True)
The message is:
Run-time error '-2147220648 (80040358)': Automation Error. Google search was less than helpful.
Here's the code for the SelectionChange event (I've only included Case "A2" and "B2" because once I figure out "B2" the rest should be identical):
Private Sub cbTransect1_SelectionChange(ByVal newIndex As Long)
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMaps As IMaps
Set pMaps = pMxDoc.Maps
Dim pIndexChipView As IMap
Set pIndexChipView = pMaps.Item(0)
Dim pMainMap As IMap
Set pMainMap = pMaps.Item(1)
Dim pGraphics As IGraphicsContainer
Set pGraphics = pMxDoc.PageLayout
pGraphics.Reset
Dim pElementProp As IElementProperties2
Set pElementProp = pGraphics.Next
Dim pTextElement As ITextElement
Do Until pElementProp Is Nothing
Select Case pElementProp.Name
Case "A2"
Set pTextElement = pElementProp
pTextElement.Text = cbTransect1.EditText
Case "B2"
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(1)
Dim pFClass As IFeatureClass
Set pFClass = pFLayer.FeatureClass
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New QueryFilter
pQueryFilter.WhereClause = "DS_DIST_MI = '" & cbTransect1.EditText & "'"
Dim pFCursor As IFeatureCursor
Set pFCursor = pFClass.Search(pQueryFilter, True)
Dim pFeature As IFeature
Set pFeature = pFCursor.NextFeature
Dim lngMaxWSE As Integer '** placeholder for B2 value
lngMaxWSE = 0
'** Getting the index pos of the MaxFlow field
Dim lngMaxWSEIndex As Long
lngMaxWSEIndex = pFClass.Fields.FindField("MAXWSEL_FT")
Do Until pFeature Is Nothing
'** Getting the cell value and adding to the total (which is 0)
lngMaxWSE = lngMaxWSE + pFeature.Value(lngMaxWSEIndex) 'this should be the value that will go in B2
Set pFeature = pFCursor.NextFeature
Loop
'set the value of B2 to lngMaxWSE
Set pTextElement = pElementProp
pTextElement.Text = lngMaxWSE
Dim pActiveView As IActiveView
Set pActiveView = pGraphics
pActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
End Sub
Any advice is appreciated.
Justin