Solved! Go to Solution.
Attached is a subset of parcels. Thanks so much for taking the time.
I'll be in the office early tomorrow.
Sub InitilizeForm Dim objLayer 'Get a reference to the first layer Set objLayer = Application.Map.Layers("Violations") Dim objEditForm Set objEditForm = objLayer.forms("EDITFORM") Dim pControls Set pControls = ThisEvent.Object.Pages("PAGE1").Controls Dim dblX, dblY dblX = Map.PointerX dblY = Map.PointerY 'Call when adding a new feature If objEditForm.Mode = 3 Then pControls("txtAddress").value = "" pControls("txtPIN").value = "" 'Find Address & PIN # from Parcels Layer Dim objParcels Set objParcels = Application.Map.Layers("Parcels") Dim rsGrid Set rsGrid = objParcels.Records Dim Rec Rec = rsGrid.FindNearestXY(dblX,dblY,0,map.Extent) If Rec > 0 Then rsGrid.MoveFirst rsGrid.move(Rec -1) pControls("txtAddress").value = rsGrid.Fields("ADDR1").Value pControls("txtPIN").value = rsGrid.Fields("PIN").Value End If End If Set objLayer = Nothing Set objEditForm = Nothing Set pControls = Nothing Set dblX = Nothing Set dblY = Nothing Set objParcels = Nothing Set rsGrid = Nothing Set Rec = Nothing End Sub
'Initialization for form when adding new records: ' When the user clicks on the map, this sets up the form. ' Call routine to automatically population some fields. ' Enable or disable controls base on data collection procedure. Sub InitializeForm Dim pLayer, objEditForm Set pLayer = Map.Layers("Violations") Set objEditForm = pLayer.forms("EDITFORM") Dim rsCurrentXY Set rsCurrentXY = Map.Layers("Violations").records rsCurrentXY.movelast Dim objXYShape Set objXYShape = rsCurrentXY.Fields.Shape Dim pControls Set pControls= ThisEvent.Object.Pages("PAGE1").Controls 'Call when adding a new feature If objEditForm.Mode = 3 Then pControls("txtAddress").value = "" ' Find corresponding map page to the valve point Set rsGrid = Map.Layers("ACPA_parcels").records rsGrid.movefirst Do While Not rsGrid.eof If rsGrid.fields.shape.Ispointin(objXYShape) Then pControls("txtAddress").value = rsGrid.Fields("ADD1").Value Exit Do End If rsGrid.Movenext Loop ' Clean Up Set rsCurrentXY = Nothing Set objXYShape = Nothing Set rsGrid = Nothing End If Set pControls = Nothing Set objEditForm = Nothing Set pLayer = Nothing End Sub
I would place the subroutine under InitializeForm(), when the edit form loads. And since this will be called each time a newly feature created, you would want it under "objEditForm.Mode = 3"
So, try to call this subroutine from Form: onload event:'Initialization for form when adding new records: ' When the user clicks on the map, this sets up the form. ' Call routine to automatically population some fields. ' Enable or disable controls base on data collection procedure. Sub InitializeForm Dim pLayer, objEditForm Set pLayer = Map.Layers("Violations") Set objEditForm = pLayer.forms("EDITFORM") Dim rsCurrentXY Set rsCurrentXY = Map.Layers("Violations").records rsCurrentXY.movelast Dim objXYShape Set objXYShape = rsCurrentXY.Fields.Shape Dim pControls Set pControls= ThisEvent.Object.Pages("PAGE1").Controls 'Call when adding a new feature If objEditForm.Mode = 3 Then pControls("txtAddress").value = "" ' Find corresponding map page to the valve point Set rsGrid = Map.Layers("ACPA_parcels").records rsGrid.movefirst Do While Not rsGrid.eof If rsGrid.fields.shape.Ispointin(objXYShape) Then pControls("txtAddress").value = rsGrid.Fields("ADD1").Value Exit Do End If rsGrid.Movenext Loop ' Clean Up Set rsCurrentXY = Nothing Set objXYShape = Nothing Set rsGrid = Nothing End If Set pControls = Nothing Set objEditForm = Nothing Set pLayer = Nothing End Sub
Rob,
Double check the indentation in your VBScript! I just did a quick test and the script returns the right value every time I add a new record (see the attached images)
[ATTACH=CONFIG]17324[/ATTACH][ATTACH=CONFIG]17325[/ATTACH]
That's strange! Have you tried to create a new ArcPad document, and add the features back in to test?
Attached is my test data...
Just tried your suggestion. Created a whole new map document. Even updated the parcel layer to a more up-to-date version and it still fills in with the exact same incorrect address and pin. (the same incorrect info from the original map) This information is stuck in the memory somewhere (which is very odd). I am frustrated and I need this to be ready tomorrow at 9am.
I'm going to redo the whole thing. Fresh check out of all the data and recreate the whole .apl and .vbs.
Unless you have any other ideas.
Thanks for your commitment to helping,
Robert
This is so strange. I have re-checked out all the data and created a new map document. I even tried it on a different computer. It simply won't work properly. The same address and pin get put in the form every time it opens no matter where i place the point.
Anyone ever have experience like this?
It seems like a problem with the record select. It isn't selecting the attributes from the Ispointin() function is it stuck on some other one.
Any ideas?