I have created some tools for a scheduling project. It allows the user to select a layer (multiple layers that they need to schedule), select features and then there is a user form that allows them to select an employee number from a drop-down box and that value gets assigned to a particular field of the selected features. It seems to work most of the time, but sometimes I get an error if I try to do a manual calucation afterwards and then it does not seem to work until I close and reopen the application. I am attaching the code for the "Assign" button (which does the field calculation) and was wondering if someone could take a look at it and see if they could spot some obvious errors with the code.
Thank you in advance!
Private Sub cmdAssign_Click()
On Error GoTo EH
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
' Get the layer that is selected in the TOC
Dim pFeatLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim pUnKnown As IUnknown
Set pUnKnown = pDoc.SelectedLayer
If pUnKnown Is Nothing Then
MsgBox "Must have a layer selected in the table of contents."
Exit Sub
End If
Set pFeatLayer = pUnKnown
Set pFeatClass = pFeatLayer.FeatureClass
Dim pFSel As IFeatureSelection
Dim pSS As ISelectionSet2
Set pFSel = pFeatLayer
Set pSS = pFSel.SelectionSet
If pSS.Count = 0 Then
MsgBox "Please select one or more features before assigning work"
Exit Sub
End If
'perform calculation
Dim pCursor As IFeatureCursor
pSS.Update Nothing, True, pCursor
Dim pCalc As ICalculator
Set pCalc = New Calculator
Dim srEmployee As String
strEmployee = cboEmp1.Text
With pCalc
Set .Cursor = pCursor
.Expression = strEmployee
.Field = "EMPSCHEDULED1"
End With
pCalc.Calculate
frmSchedule.Hide
Exit Sub
EH:
MsgBox Err.Number & " " & Err.Description
End Sub