Newbie: Trying to populate one field based on choice in another field

2221
3
03-25-2013 08:59 AM
MichaelBishopp
Occasional Contributor
I am new to ArcPad and new to VBS, so this might be a bit more than I can chew, but here goes:

I have a rather long table that has a code field (sign type) and a description field (sign description).  I want my ArcPad users to be able to choose from the Description field and have the code field automatically fill in based on that choice.

I'm assuming that I need to create some sort of a domain table (maybe a .dbf table??) that can be linked to the Description field.  From this table the coded value (sign type) would be known, so that it could be automatically populated into the "sign type" field.

Can anyone help direct me on how to go about this?

Michael:confused:
Tags (3)
0 Kudos
3 Replies
KariBuckvold
Occasional Contributor
Did you figure this out? I'm looking to do something similar.
0 Kudos
MichaelBishopp
Occasional Contributor
Did you figure this out? I'm looking to do something similar.


I did find some code that got me started.  Here it is:

'autopopulate a field based on entry in another field
Sub AutoPop

 Dim objDBF, strCode, strTest, i , strObs, pageGen
 'pageGen = Layers("SignsTest3").Forms("EDITFORM").Pages("General") 'SignsTest3 is the layer
 strObs= Layers("SignsTest3").Forms("EDITFORM").Pages("General").Controls("domDescription").value 'get value user selected in domDescription field
 Set objDBF = Application.CreateAppObject("recordset")   
 objDBF.Open "C:\Users\mbishopp\Documents\SignsTestData1\dbase\Example.dbf", 1  'open the external DBF table <--this should probably be placed somewhere else, like with the apl or axf, but I was just experimenting at the time.
 
 objDBF.MoveFirst 
 For i=0 to objDBF.RecordCount-1   'loop through DBF list until end of list 

  If strObs=objDBF.Fields("Descriptio").Value then 'compare selected obs value form with 1st CODE value from table
      

   strTest = objDBF.Fields("SignType").Value 'if form value = CODE value then store associated TEST value in variable
   MsgBox(strTest)
   Layers("SignsTest3").Forms("EDITFORM").Pages("General").Controls("tbSignType").value = strTest 'Populate the tbSignType control with var strTest
   Layers("SignsTest3").Forms("EDITFORM").Pages("General").Controls("tbDescription").value = strObs 'Populate the tbDescription control with var strObs
   'ThisEvent.Object.value=strTest   'enter stored variable into text box on form <--didn't use this, legacy from other user that I stole this from :)
  Else  
  End If
 objDBF.MoveNext  'goto next record in DBF table
 Next
 
 objDBF.Close    'close DBF table

 Set objDBF = Nothing 

End Sub


Hopefully that helps!
0 Kudos
ValentinWittich
New Contributor III
I solved the same problem pretty simple.

You can try it with a test.shp with two filed NAME and DESC. Your APL needs two combo boxes which active a script after changing:
<ArcPad>
 <LAYER name="test.shp">
  <FORMS>
   <EDITFORM name="EDITFORM" caption="test" width="130" height="130" picturepagevisible="false" attributespagevisible="false" symbologypagevisible="false" geographypagevisible="false" required="false">
    <PAGE name="PAGE1" caption="test">
     <COMBOBOX name="NAME" x="32" y="22" width="94" height="100" defaultvalue="" listtable="list.dbf" listvaluefield="NAME" listtextfield="NAME" onselok="Call UpdateNameList()" tooltip="" tabstop="true" border="true" sip="true" limittolist="false" sort="false" field="NAME"/>
     <COMBOBOX name="DESC" x="32" y="22" width="94" height="100" defaultvalue="" listtable="list.dbf" listvaluefield="DESC" listtextfield="DESC" onselok="Call UpdateDescList()" tooltip="" tabstop="true" border="true" sip="true" limittolist="false" sort="false" field="SPECIES"/>
    </PAGE>
   </EDITFORM>
  </FORMS>
  <SCRIPT src="Functions.vbs" language="vbscript"/>
 </LAYER>
</ArcPad>

Now you need your list.dbf with a row called NAME and DESC in the same folder as well as the Functions.vbs:
Sub UpdateNameList()
 
 Dim pForm
 Set pForm = ThisEvent.Object.Parent
 
 pForm.Controls("NAME").ListIndex = pForm.Controls("DESC").ListIndex
 
 Set pForm = Nothing

End Sub

Sub UpdateDescList()
 
 Dim pForm
 Set pForm = ThisEvent.Object.Parent
 
 pForm.Controls("DESC").ListIndex = pForm.Controls("NAME").ListIndex
 
 Set pForm = Nothing

End Sub


Hope that works out... The basics idea is that both list have the same Index...

Regards Valentin
0 Kudos