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

7770
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
22 Replies
ThaiTruong
Occasional Contributor II
You're getting close there... 🙂

OK, paste the following code to your applet VBScript file:

Option Explicit

Sub PopulateForm()
Dim objForm, objPage, objControl
Set objForm = Application.Map.Layers(Application.UserProperties("LayerName")).Forms("EDITFORM")
Set objPage = objForm.Pages("PAGE1")
Set objControl = objPage.Controls

If objControl.Item("Subtype").value = "1" Then
 objControl.Item("IDfield1").Enabled = True
 objControl.Item("IDfield1").Value = ""
 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("IDfield1").Value = ""
 objControl.Item("IDfield2").Enabled = True
 objControl.Item("IDfield2").Value = ""
 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
 objControl.Item("IDfield3").Value = ""

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
End Sub


Under OnSelChange Event of your combo box control, add these script:

' Define public value for Layer Name
Application.UserProperties("LayerName") = "CurrentLayerName"
' Call PopulateForm() in applet
Application.Applets("AppletName").Execute("PopulateForm")


For the above script, change "CurrentLayerName" to your layer name and "AppletName" to your Applet's name.

So, the advantage for doing this is next time you want to modify values based on selection from the 1st combo box, all you have to do is to modify the code under PopulateForm()

Hope you get the idea.  Have fun coding... 🙂
0 Kudos
kg76
by
Occasional Contributor
Great - thank you. I'm still getting Script Error 800A01A8 - Object required: 'Application.Map.Layers(...)' [Line: 11, Column 1] Source Text Unavailable. I'm receiving the error both in ArcPad on my desktop and in ArcPad on my GPS unit. Here is my code:

Option Explicit
'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()

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

Set objForm = Application.Map.Layers(Application.UserProperties("LayerName")).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


Thanks,

Kerry
0 Kudos
ThaiTruong
Occasional Contributor II
Kerry,

What's the code you have under OnSelChange Event?
You need to create a global value "LayerName":
'for your line feature "Line" = name of the layer
Application.UserProperties("LayerName") = "Line"
0 Kudos
kg76
by
Occasional Contributor
Thanks Thai - This is what I had per your last post in the onselchange event of my combo box (in the line layer definition of my axf):

' Define public value for Layer Name
Application.UserProperties("LayerName") = "Line"
' Call PopulateForm() in applet
Application.Applets("AppletEnableIDfields").Execute("PopulateForm")

I have this same script also in the onload event of my form properties.
0 Kudos
ThaiTruong
Occasional Contributor II
Kerry,

It works for me.  I used Riverside.axf to test this code (see the attached PNG below)

If possible, post your AXF file here, I'll try to iron out the issue for you.
0 Kudos
kg76
by
Occasional Contributor
Thai - my applet and .axf file are attached. Thank you for looking at it.

Kerry
0 Kudos
ThaiTruong
Occasional Contributor II
Kerry -

1.  Open AppletEnableIDfields.apa with ArcPad Studio and delete OnStartUp event under APPLICATION.
2.  Re-edit your VBScript. and change "lblSUBTYPE" to 1, 2, 3, and 4 respectively.  You need to set it = to the code value.
'If lblSUBTYPE field value is Site, do the following:
If objControl.Item("lblSUBTYPE").Value = 1 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 = 2 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 = 3 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 = 4 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


3.  Back to your AXF, open your Line Feature Layer.  Remove or comment out your code in Layer2.vbs
4.  Optional, I dont think you need OnLoad Event under EDITFORM either!
5.  Save everything and add Line to your ArcPad map document and test your script.  It should work for you this time.
6.  Do the same above steps for your Point & Polygon feature layers.

Good luck! 🙂
0 Kudos
kg76
by
Occasional Contributor
I made those changes and I'm still getting an error specific to the objForm. I've attached a screenshot of the error. I want to keep the for the onload of the EDITFORM because I've got different symbology for my subtypes separated out in my QuickCapture toolbar so if you pick the red triangle, subtype 1 should appear filled in on the form automatically and hide those unnecessary fields when the form appears. If I remove it, the data collector has to select a subtype manually. I reattached my .axf and applet with the changes made.

Thanks,

Kerry
0 Kudos
ThaiTruong
Occasional Contributor II
Kerry,

You forgot to include a vbscript file for the applet in your zip file above.

download this new zip file, extract it to a location on your PC.  Open up ArcPad, and set the path to applets under ArcPad options.  Restart ArcPad and add your features to edit.

It works for me, so I hope it'll work for you as well... 🙂
0 Kudos
kg76
by
Occasional Contributor
OK that works! But, I realize now that I didn't communicate this but I'm using Trimble Positions to check out data from my geodatabase. So during the check out process when a new .axf file is created, I set the .axf layer definitions to my custom .axf. I then open the .apm that is also created in the check out process in ArcPad on either the desktop or on my GPS unit and try to add a point and that's when I'm getting the script error. I should have mentioned this sooner. When I tried it your way just opening ArcPad and adding in layers then it worked.

Kerry
0 Kudos