Im working on building a very simple tool that will record the date/time, XY coordinates after a user clicks on the map.
The code is crashing when it reaches 'pFeature.Value(pFeature.Fields.FindField("CurDate")) = Me.txtDate.Text'. Do I need to create a new row first to store the values? The VBA script worked without creating a new row, so I'm just curious where I am going wrong.
The code is crashing when it reaches 'pFeature.Value(pFeature.Fields.FindField("CurDate")) = Me.txtDate.Text'. Do I need to create a new row first to store the values? The VBA script worked without creating a new row, so I'm just curious where I am going wrong.
Code:
Private Sub cmdExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Click
Dim pMxDoc As IMxDocument
pMxDoc = My.ArcMap.Application.Document
Dim pMap As IMap
pMap = pMxDoc.FocusMap
Dim pFtrLyr As IFeatureLayer
pFtrLyr = pMxDoc.SelectedLayer
If pFtrLyr Is Nothing Then
MsgBox("A Single Layer Must Be Selected", vbExclamation, "Edit Selected Layer")
Exit Sub
End If
Dim pFeature As IFeature
pFeature = pFtrLyr.FeatureClass.CreateFeature
pFeature.Shape = Module1.pPoint
' Get and set the spatial reference of new layer and new point
Dim pBasicMap As IBasicMap
pBasicMap = pMap
pFtrLyr.SpatialReference = pBasicMap.SpatialReference
pPoint.SpatialReference = pBasicMap.SpatialReference
pFeature.Value(pFeature.Fields.FindField("CurDate")) = Me.txtDate.Text ***Crashes Here****
pFeature.Value(pFeature.Fields.FindField("CurTime")) = Me.txtTime.Text
pFeature.Value(pFeature.Fields.FindField("Type")) = Me.txtType.Text
pFeature.Store()
pMxDoc.UpdateContents()
pMxDoc.ActiveView.Refresh()
Me.Close()
End Sub