Select to view content in your preferred language

trying to use button initiated sub forms instead of tabs...help

1984
6
12-09-2010 08:18 AM
markfarina
Emerging Contributor
I was hoping some one could help me with this form example....Instead of using tabs, I would like to use buttons to open sub forms. I would like the data to reside in those sub forms.

Question 1 see illustration: The data selected (A or B) in the subform fields will not save to my pointlayer. It seems that my pointlayer will not link to the fields populated in the subform. How do I fix this?

Question 2 see illustration: I would like the fields of data to stay in the subform but display for quick user reference in the fields on the main form. For example on 'onok' I would need to have the fields in the subform build a string to display in the parent form. Any ideas on this?

Code apl
<LAYER name="pointlayer.shp" autopack="false">
<FORMS>
<EDITFORM name="EDITFORM" caption="Pointlayer" width="130" height="130" tabsvisible="true" picturepagevisible="false" symbologypagevisible="false" geographypagevisible="true" attributespagevisible="false" backgroundcolor="Green">
<PAGE name="pgViewer" caption="View">
<LISTBOX name="listData" x="50" y="2" width="50" height="12" defaultvalue="" tabstop="true" border="true"/>
<BUTTON name="cmdAdd" x="1" y="2" width="30" height="14" onclick="Call OpenAddNew1" caption="Site1" tabstop="true" alignment="center"/>
<LISTBOX name="listData2" x="50" y="20" width="50" height="12" defaultvalue="" tabstop="true" border="true"/>
<BUTTON name="cmdAdd2" x="1" y="20" width="30" height="14" onclick="Call OpenAddNew2" caption="Site1" tabstop="true" alignment="center"/>
</PAGE>
</EDITFORM>
<FORM name="frmAddNew" caption="Site1" width="130" height="80" tabsvisible="false">
<PAGE name="PAGE1" caption="page1" page="page1" backgroundcolor="white">
<LABEL name="LABEL29" caption="thing1" x="3" y="3" width="25" height="12" tooltip=""/>
<COMBOBOX name="thing1" field="thing1" x="25" y="2" width="30" height="12" border="true" tabstop="true" tooltip="" limittolist="false">
<LISTITEM value="A" text="A"/>
<LISTITEM value="B" text="B"/>
</COMBOBOX>
<LABEL name="LABEL30" caption="thing2" x="3" y="20" width="25" height="12" tooltip=""/>
<COMBOBOX name="thing2" field="thing2" x="25" y="20" width="30" height="12" border="true" tabstop="true" tooltip="" limittolist="false">
<LISTITEM value="A" text="A"/>
<LISTITEM value="B" text="B"/>
</COMBOBOX>
</PAGE>
</FORM>
</FORMS>

Code vbs

Option Explicit

Sub OpenAddNew1
Dim aForm
set aForm=Application.Map.Layers("pointlayer").Forms("frmAddNew")
aForm.Show
End Sub
Tags (3)
0 Kudos
6 Replies
markfarina
Emerging Contributor
Ok, I figured out question 2 on my previous post.  I inserted onok="Call WriteToField1" from the apl subform and used the script below in the vbs. This puts the subform combobox items into a string on the main form for display.

And also changed the display field from listbox to edit field.



Sub WriteToField1

Dim obj
Set obj = ThisEvent.Object
If Not obj.Mode = 1 Then
Dim pPageH1, pPageH2
Set pPageH1 = ThisEvent.Layer.Forms("EDITFORM").Pages("pgViewer")
Set pPageH2 = ThisEvent.Layer.Forms("frmAddNew").Pages("page1")

pPageH1.Controls("listdata").Value = pPageH2.Controls("thing1").Value & ", " & pPageH2.Controls("thing2").value



End If

End Sub
0 Kudos
markfarina
Emerging Contributor
Still cannot figure out why the fields in the subform comboboxs will not save to the associated field in the pointlayer.

Does anybody know how to do this?

Thanks
0 Kudos
EricMcPhee
Regular Contributor
I think to get your values to save to the point layer, you need to save them to the 'field'. Your current code is only saving the values to the control of your form (pPageH1.Controls("listdata").Value). Instead try saving the values to the field that is behind the control......like this:
ThisEvent.Layer.Forms("EDITFORM").Fields("%YourField%").Value = pPageH2.Controls("thing1").Value & ", " & pPageH2.Controls("thing2").value
0 Kudos
markfarina
Emerging Contributor
Eric, (or anyone)

I wasn't able to get this code to work out for my problem....

So what your saying is I need to assign the two combobox selections (thing1,thing2) which are on the subform to fields so they will save to the pointlayer? They are currently only controls?

The script I used.....(pPageH1.Controls("listdata").Value = pPageH2.Controls("thing1").Value & ", " & pPageH2.Controls("thing2").value)....strings the the thing1 and thing2 values into a field called listdata on the main form.  This does what I need it to do and is intended to display a summary to the user only.

I just need "thing1" and "thing2" comboboxs in the subform to save to their correct fields in the pointlayer.  I would think they would need to save to some sort of temporary hidden field because there are no individual edit boxs for thing1 and thing2 on the main form....

Thanks
0 Kudos
EricMcPhee
Regular Contributor
In you WritetoField1 sub routine, you need to set the values for the "fields" (thing1 and thing2). Try this:

Sub WriteToField1

Dim obj
Set obj = ThisEvent.Object
If Not obj.Mode = 1 Then
Dim pPageH1, pPageH2
'set a reference to the fields...these need to be the actuall field names in your data (shapefile of .axf)
dim T1, T2
set T1 = ThisEvent.Layer.Forms("EDITFORM").Fields("thing1")
set T2 = ThisEvent.Layer.Forms("EDITFORM").Fields("thing2")

Set pPageH1 = ThisEvent.Layer.Forms("EDITFORM").Pages("pgViewer" )
Set pPageH2 = ThisEvent.Layer.Forms("frmAddNew").Pages("page1")

pPageH1.Controls("listdata").Value = pPageH2.Controls("thing1").Value & ", " & pPageH2.Controls("thing2").value

'set the values of the fields thing1 and thing2
T1.value = pPageH2.Controls("thing1").Value
T2.value = pPageH2.Controls("thing2").value


End If

End Sub


I realize this code looks crude, but it should give you the idea.
0 Kudos
markfarina
Emerging Contributor
Thanks Eric!  That did the trick.
0 Kudos