Select to view content in your preferred language

Store new feature in featureclass, Create new Row?

445
1
04-01-2013 08:31 AM
BrianBaldwin1
Deactivated User
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.


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
0 Kudos
1 Reply
NeilClemmons
Honored Contributor
If the field is a true Date field then need to set its value using a Date.  Convert the textbox value to a Date type and it should work.
0 Kudos