Make Fields Visible / Hide Fields with Values based on Combo Box Selection

7815
22
Jump to solution
05-20-2013 12:53 PM
kg76
by
Occasional Contributor
I have an EDITFORM with a page called DataEntry. On the DataEntry page I have a combo box (called Subtype) and three ID text fields. Based on the value selected in the combo box, I need certain combinations of those ID fields to be visible, if applicable, or hidden with a value of "N/A" if not applicable, as described below:

If Subtype = 1
Then:
IDfield1 = Visible
IDfield2 = Hidden with value "N/A"
IDfield3 = Hidden with value "N/A"

If Subtype = 2
Then:
IDfield1 = Visible
IDfield2 = Visible
IDfield3 = Hidden with value "N/A"

If Subtype = 3
Then:
IDfield1 = Hidden with value "N/A"
IDfield2 = Hidden with value "N/A"
IDfield3 = Visible

If Subtype = 4
Then:
IDfield1 = Hidden with value "N/A"
IDfield2 = Hidden with value "N/A"
IDfield3 = Hidden with value "N/A"

I was hoping to be able to do this in my geodatabase with subtype default values as "N/A" where appropriate, but alas, ArcPad does not honor default values for subtypes. I cannot have the default values at the field level because then the data recorder would be able to collect a point without changing any "N/A" values.

I don't have a whole lot of experience with VB scripting in ArcPad studio, and I'm thinking I need to use the OnLoad event for the DataEntry page and the OnSelChange event for the Subtype combo box but I'm not exactly sure how to do this.

I've read this old post that seems similar to what I'm trying to achieve http://forums.esri.com/Thread.asp?c=93&f=1180&t=124519&g=1

Any help would be greatly appreciated.

Thanks,

Kerry
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
kg76
by
Occasional Contributor
Ok, I figured out why I was getting a scripting error through the Trimble Positions check out process...my layer names in the check out process didn't match the script.

Thank you VERY much for your help Thai!

Kerry

View solution in original post

0 Kudos
22 Replies
ThaiTruong
Occasional Contributor II
Kerry,

You're heading in the right direction there...
Under the "OnChange" event of your subtype combo box control, you'll need to call a custom function to populate values to the other 3 text controls.

Here is a sample code to help you manipulate and populate value of the 3 text controls with assumtions:
your layer's name is "YourLayer"
your form's name is "DataEntry"
Page's name for the controls = "PAGE1"
your controls' names = "Subtype", "IDfield1", "IDfield2", and "IDfield3"

Dim objForm, objPage, objControl

Set objForm = Map.Layers("YourLayer").Forms("DataEntry")
Set objPage = objForm.Pages("PAGE1")
Set objControl = objPage.Controls

If objControl.Item("Subtype").value = "1" Then
 objControl.Item("IDfield1").Enabled = True
 objControl.Item("IDfield2").Enabled = False
 objControl.Item("IDfield2").Value = "N/A"
 objControl.Item("IDfield3").Enabled = False
 objControl.Item("IDfield3").Value = "N/A"

ElseIf objControl.Item("Subtype").value = "2" Then
 objControl.Item("IDfield1").Enabled = True
 objControl.Item("IDfield2").Enabled = True
 objControl.Item("IDfield3").Enabled = False
 objControl.Item("IDfield3").Value = "N/A"

ElseIf objControl.Item("Subtype").value = "3" Then
 objControl.Item("IDfield1").Enabled = False
 objControl.Item("IDfield1").Value = "N/A"
 objControl.Item("IDfield2").Enabled = False
 objControl.Item("IDfield2").Value = "N/A"
 objControl.Item("IDfield3").Enabled = True

ElseIf objControl.Item("Subtype").value = "4" Then
 objControl.Item("IDfield1").Enabled = False
 objControl.Item("IDfield1").Value = "N/A"
 objControl.Item("IDfield2").Enabled = False
 objControl.Item("IDfield2").Value = "N/A"
 objControl.Item("IDfield3").Enabled = False
 objControl.Item("IDfield3").Value = "N/A"
End If

'Free objects
Set objControl = Nothing
Set objPage = Nothing
Set objForm = Nothing


Have fun coding.... 🙂
0 Kudos
kg76
by
Occasional Contributor
Thanks Thai - this helps me a lot. Just one more question...this script would apply to nine layers (three feature datasets with three feature classes each). Do I just list them, or do I need to code it so that the script applies to the active layer?
0 Kudos
ThaiTruong
Occasional Contributor II
Are you trying to update all 9 layers with the values in this form at once?!
0 Kudos
kg76
by
Occasional Contributor
No, so I'll have three layers checked out at any given time, a point, line, and polygon with the same subtypes. I tried to design my .axf file generically so that any one of my feature datasets could use it in the checkout process. I need the script to run for whatever point, line, or polygon layer that I'm either collecting for or editing at the time. Does that make sense? Thanks.
0 Kudos
ThaiTruong
Occasional Contributor II
Yes, it's doable.  Just create a sub for this in your applet and call it when you need it.

Ex:
Sub PopulateForm(c_sFLayer)
Dim objForm, objPage, objControl

Set objForm = Map.Layers(c_sFLayer).Forms("DataEntry")
Set objPage = objForm.Pages("PAGE1")
Set objControl = objPage.Controls
...
End Sub


Then just call PopulateForm() and pass the layer name of your point, polyline, or polygon to it.
0 Kudos
kg76
by
Occasional Contributor
Do I have to create an applet? Or can I just include the script in my .axf file?
0 Kudos
ThaiTruong
Occasional Contributor II
I would put this event handler in an applet.  Think of ArcPad applet as a module that runs inside ArcPad application and it contains public form, tools, and system object event handlers that access the ArcPad object model through scripts.
0 Kudos
kg76
by
Occasional Contributor
Thank you for answering my questions so promptly and helping with this! So I'm still a little bit fuzzy on a couple of things as I'm new to VBscript. In the first code block, am I supposed to replace "YourLayer" with c_sFLayer or should I be using ThisEvent.Object? Also, I need my custom forms to be in my .axf file and not in an applet. Can I call the script from the applet in the events of the layer definition of my .axf? Thanks.
0 Kudos
kg76
by
Occasional Contributor
Ok here's what I've got.

'The purpose of this script is to enable the appropriate ID/NUMBER fields [ASMIS_ID, FEATURE_NUMBER, TRACKING_NUMBER] 
'when a given subtype [Site, Feature, IO, Other] is selected, and to hide those ID/NUMBER fields that do not apply with the value "N/A".

'Create a subroutine to be able to pass any feature layer name to the script
Sub PopulateForm(c_sFLayer)

'Create and define Form, Page, and Control
Dim objForm, objPage, objControl

Set objForm = Map.Layers(c_sFLayer).Forms("EDITFORM")
Set objPage = objForm.Pages("DataEntry")
Set objControl = objPage.Controls

'If lblSUBTYPE field value is Site, do the following:
If objControl.Item("lblSUBTYPE").value = "Site" Then
 'Enable txtASMIS_ID field
 objControl.Item("txtASMIS_ID").Enabled = True
 'Disable txtFEATURE_NUMBER field
 objControl.Item("txtFEATURE_NUMBER").Enabled = False
 'and set value of txtFEATURE_NUMBER field to "N/A"
 objControl.Item("txtFEATURE_NUMBER").Value = "N/A"
 'Disable txtTRACKING_NUMBER field
 objControl.Item("txtTRACKING_NUMBER").Enabled = False
 'and set value of txtTRACKING_NUMBER field to "N/A"
 objControl.Item("txtTRACKING_NUMBER").Value = "N/A"

'If lblSUBTYPE field value is Feature, do the following:
ElseIf objControl.Item("lblSUBTYPE").value = "Feature" Then
 'Enable txtASMIS_ID field
 objControl.Item("txtASMIS_ID").Enabled = True
 'Enable txtFEATURE_NUMBER field
 objControl.Item("txtFEATURE_NUMBER").Enabled = True
 'Disable txtTRACKING_NUMBER field
 objControl.Item("txtTRACKING_NUMBER").Enabled = False
 'and set value of txtTRACKING_NUMBER field to "N/A"
 objControl.Item("txtTRACKING_NUMBER").Value = "N/A"

'If lblSUBTYPE field value is IO, do the following:
ElseIf objControl.Item("lblSUBTYPE").value = "IO" Then
 'Disable txtASMIS_ID field
 objControl.Item("txtASMIS_ID").Enabled = False
 'and set value of txtASMIS_ID field to "N/A"
 objControl.Item("txtASMIS_ID").Value = "N/A"
 'Disable txtFEATURE_NUMBER field
 objControl.Item("txtFEATURE_NUMBER").Enabled = False
 'and set value of txtFEATURE_NUMBER field to "N/A"
 objControl.Item("txtFEATURE_NUMBER").Value = "N/A"
 'Enable txtTRACKING_NUMBER field
 objControl.Item("txtTRACKING_NUMBER").Enabled = True

'If lblSUBTYPE field value is Other, do the following:
ElseIf objControl.Item("lblSUBTYPE").value = "Other" Then
 'Disable txtASMIS_ID field
 objControl.Item("txtASMIS_ID").Enabled = False
 'and set value of txtASMIS_ID field to "N/A"
 objControl.Item("txtASMIS_ID").Value = "N/A"
 'Disable txtFEATURE_NUMBER field
 objControl.Item("txtFEATURE_NUMBER").Enabled = False
 'and set value of txtFEATURE_NUMBER field to "N/A"
 objControl.Item("txtFEATURE_NUMBER").Value = "N/A"
 'Disable txtTRACKING_NUMBER field
 objControl.Item("txtTRACKING_NUMBER").Enabled = False
 'and set value of txtTRACKING_NUMBER field to "N/A"
 objControl.Item("txtTRACKING_NUMBER").Value = "N/A"
End If

'Free objects
Set objControl = Nothing
Set objPage = Nothing
Set objForm = Nothing


End Sub


In the form properties > OnLoad event, and in the subtype field's properties > OnChange event I called PopulateForm("Line") for the Line layer and so on. In ArcPad when I try to collect a point and the form loads, I receive the following error:

Script Error 800A000D
Error Source Unavailable
Error Description Unavailable
[Line: 1, Column: 1]
Source Text Unavailable

What's missing?

Thanks,

Kerry
0 Kudos