Populating a form page with pre-existing values

619
3
06-16-2011 07:14 AM
Almarde_Ronde
New Contributor
Dear Forum,

I would like to re-edit a previously saved point feature. So I am trying the following:

Set pLayer = Application.Map.Layers("myLayerName")
If not pLayer.Editable = True
pLayer.Editable = True
End If
pLayer.Edit intBookmark

This opens up the EditForm of myLayerName in Form Mode 2 (="Editing an exisiting feature"). How can I populate the fields of the EditForm with the values that are already stored in the point feature?

Currently each field in the EditForm is blank.

Thanks for any help! Almar
Tags (3)
0 Kudos
3 Replies
EricHajek1
Occasional Contributor
If the values for textboxes / comboboxes aren't being automatically populated and the textboxes / comboboxes are tied to a field, then that's sort of weird, but in any case they could be accessed and assigned like this:

pLayer.Records.Fields("fieldname").value   'Accesses the value of a field after a bookmark has been set

You'll need to access the editform/page/control itself, which you can do a bunch of ways, but since you have pLayer already specified:

pLayer.Forms("EDITFORM").Pages("pagename").Controls("controlname").value

Combining these two statements we get:

pLayer.Forms("EDITFORM").Pages("pagename").Controls("controlname").value = pLayer.Records.Fields("fieldname").value

You might put these statements in the onload event of the form rather then the level (applet?) you're calling the other code from.

From inside events, it's easy to get references to things by using ThisEvent.Object, which returns the object associated with the event being fired. For onload of an editform, ThisEvent.Object gets you a reference to the form, and could alter the above statement like this:

ThisEvent.Object.Pages("pagename").Controls("controlname").value

Pages and controls have events as well, so you can hook into stuff at ant level.

Hope this helps! If you have any other more specific questions I'll do my best to answer.
0 Kudos
Almarde_Ronde
New Contributor
Dear Eric,

Thanks for replying. Yes, I was actually trying to use the OnLoad event of the Editform to set values before, but it just doesn't work. The code "pLayer.Edit" is not in an applet, just as part of the AXF layer, and all form fields are tied to feature fields. Strangely enough, if I just use a line like

Application.ExecuteCommand ("featureproperties")

on the editable layer, it all works fine. The OnLoad event is triggered, and all fields are populated.

I'll have a go with your suggestions, let you know the outcome.

Cheers,

Almar.
0 Kudos
Almarde_Ronde
New Contributor
My problem has been solved, turns out I was working with an incorrect bookmark.

The EditForm now shows up with all pre-existing values. Getting the field values of the point being re-edited during the OnLoad of the EditForm is actually quit straight forward by using something like

Dim pForm, pFields
Set pForm = ThisEventObject 'ThisEventObject = EditForm object
If pForm.mode = 2 'Editing existing features
pFields = ThisEventObject.Fields
etc
End If

"The Fields property references the fields of the current record in an Edit Form. This allows you to access fields that are not necessarily bound to any controls on the form." (manual)
0 Kudos