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?
Sorry to hear that! Did my attached example work for you?If it's not a big deal, post your 2 features, apl files, and vbs in here. I'll try to look into it for you.
I figured out the problem!~ but not the solution.So when I click to create a feature, the correct attribute fill in the table, BUT if I click Cancel rather than Ok to accept the new feature (something that could happen in the field if the inspector clicks the wrong place), when I click a new location the old locations attributes are still stuck in the record select and the form waiting to be accepted.So is there a way to code in "If the point doesn't get placed (the user clicks cancel) it clears all of the attributes stored"PROGRESS!!THANKS!
Just a curiosity, did you toggle the "Repeat Attribute" button?!However, I don't think it's matter because if you code it right, your address and pin values will be overwrited each time you place a new point!
Attached is the .apx file with the code in it. You can make you your own polygon layer. The parcel layer is too large to send unless you have dropbox or something similar.Thanks!
Your code above does not work for AXF files. You need to modify it and use DataSource object, then call Openlayer method to get the Recordset. As of now, your code above only works with shapefiles.If you can provide me a few records from ACPA_parcels and export those features out to a shapefile, I can help you with the coding tomorrow.I need a parcel feature that has the same projection with your point file.
Because you have a large parcels dataset, using IsPointIn() will slow down your data capture process. it has to loop through all the records inside your pacel layer to find one that contains the point.So, in your case, I would use FindNearestXY() to find a parcel intersected with the collected point. This will perform much better on a large datasets like your.So, here is a new "InitilizeForm" sub for you. Let me know if it works for you. 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
Brilliant! It works flawlessly. Thank you so very much for your dedication to this community.
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 pPt Set pPt = Application.CreateAppObject("Point") pPt.X = Map.PointerX pPt.Y = 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 rsGrid.movefirst Do While Not rsGrid.eof If rsGrid.Fields.Shape.Ispointin(pPt) Then pControls("txtAddress").value = rsGrid.Fields("ADDR1").Value pControls("txtPIN").value = rsGrid.Fields("PIN").Value Exit Do End If rsGrid.Movenext Loop End If Set objLayer = Nothing Set objEditForm = Nothing Set pControls = Nothing Set pPt = Nothing Set objParcels = Nothing Set rsGrid = Nothing End Sub
I'm glad that it works for you, and hope that you don't find my house to be in violation of irrigation codes! 🙂BTW, here's an example on how IsPointIn() works: 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 pPt Set pPt = Application.CreateAppObject("Point") pPt.X = Map.PointerX pPt.Y = 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 rsGrid.movefirst Do While Not rsGrid.eof If rsGrid.Fields.Shape.Ispointin(pPt) Then pControls("txtAddress").value = rsGrid.Fields("ADDR1").Value pControls("txtPIN").value = rsGrid.Fields("PIN").Value Exit Do End If rsGrid.Movenext Loop End If Set objLayer = Nothing Set objEditForm = Nothing Set pControls = Nothing Set pPt = Nothing Set objParcels = Nothing Set rsGrid = Nothing End Sub
Thanks again! I currently have the Lat/Lon fields filled in using GPS.Latitude and GPS.Longitude. However, if they do not have a gps signal (such as in the office) and they want to add a violation based on a complaint (people call and say "soandso is watering when they are not supposed to" I would like these fields to be filled in based on where they clicked on the map.Is it possible to grab Lat/Lon from the map and not the GPS unit?I know about Map.PointerX/Y, but those give me state plane coordinates and I want DD. Is there a simple conversion scripts perhaps?Thanks
... Dim pPt Set pPt = Application.CreateAppObject("Point") pPt.X = Map.PointerX pPt.Y = Map.PointerY Dim pLLCS 'define a coordinate system Set pLLCS = Application.CreateAppObject( "CoordSys" ) pLLCS.Import("C:\Program Files (x86)\ArcGIS\ArcPad10.0\Coordinate System\Geographic Coordinate Systems\World\WGS 1984.prj") Dim pDstPoint Set pDstPoint = pLLCS.Project(pPt) msgbox("the DD coordinate is " & pDstPoint.X & ", " & pDstPoint.Y) ...
I am running into a new problem now!When my field technician reopens a feature for editing (such as adding information concerning when he mailed a written warning, follow up inspection date, etc) The address and pin fields are changing to erroneous values. Is there a way to make the script run ONLY WHEN NEW FEATURES ARE CREATED and not just when the edit form loads? or is there a way to LOCK the fields once they have been filled in once? or can I make the script not fill in the attributes if there is already text in the control box?Thanks in advance!!!
Sub InitializeForm 'Do any form initialization in this sub If objEditForm.Mode = 3 Then 'Things to do when create a new feature go here End If If objEditForm.Mode = 2 Then 'Things to do when edit an existing feature go here End If End Sub
A lot of good info here. I have a quick question along the same idea. What would it take to return the address number from parcels on each side of the parcel clicked on? For example, 123 is to the left of the clicked parcel and 127 is to the right of the clicked parcel.Thanks and God bless!
I've been following this thread because I was trying to do something similiar and do not have any programming experience. Thank you for assiting in making a challenge less difficult for me. I was able to modify this code to accomplish what I needed to but found that I need to place my parcels shapefile into the same directory with the shapefile that I am modifying. Normally all my basemap data is located in other directories to keep them separate from data that is being collected or modified, especially since there is a lot of basemap data. I tried modifying the path to the location where the parcels reside but that resulted in an error, source object not found. My question, how do I modify the script to point to my directory where my parcels are located, or is that not possible?Parcels reside in C:\GIS\Shapefiles\Parcels\Polygons\Parcels.shpThe line below is the one that currently works as long as the parcels reside in the same directory:Set objParcels = Application.Map.Layers("Parcels")Thanks.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.