Select to view content in your preferred language

Script autonumber in ArcPad 10

3056
1
04-06-2011 01:31 AM
LucienDavids
Emerging Contributor
Hi,

I have an autonumber script that worked fine in ArcPad 7 with shapefiles. Now I am trying to get this script to work in ArcPad 10 wihtin an AXF. As you allready can imagine it gives an error, otherwise I would not create a new thread ;).

The script I am trying to use:

Option Explicit

Sub autonumber
'Do any form initialization in this sub
Dim objEFPageOneControls, objEditForm
Set objEditForm = ThisEvent.Object
Set objEFPageOneControls = objEditForm.Pages("form").Controls
'Initialization for form in any mode
'Disable the Tree ID edit box
objEFPageOneControls("txtElmId").Enabled = False
'Initialization for form when adding new records
If objEditForm.Mode = 3 Then
'Initialize DATE to current date objEFPageOneControls("dtpDate").Value = Now
'Get the City Trees layer's recordset (to pass into the ReturnNextID function)
Dim objCityTreesRS
Set objCityTreesRS = Layer.Records
'Update the Tree ID
objEFPageOneControls("txtElmID").Value = ReturnNextID (objCityTreesRS, "ElmID")
End If
'Free objects Set objEFPageOneControls = Nothing
Set objEditForm = Nothing
Set objCityTreesRS = Nothing
End Sub

Function ReturnNextID (objRS, strFieldName)
  Dim intMax
  'Get the first record
  objRS.MoveFirst
  'Initialize the max value to the first record
  intMax = CInt(objRS.Fields(strFieldName).Value)
  'Loop through the records, updating the max value if necessary
  Dim intCurrVal
  While Not objRS.EOF
    intCurrVal = CInt(objRS.Fields(strFieldName).Value)
    If (intCurrVal > intMax) Then
      intMax = intCurrVal
    End If
    objRS.MoveNext
  Wend
  ReturnNextID = intMax + 1
End Function

It gives an script error 800A000D

I really like to get this to work under 10. For many applications an own auto numbering is needed.

Kind regards,

Lucien
Tags (3)
0 Kudos
1 Reply
JasonTipton
Frequent Contributor
I don't know what your exact problem is, but don't cuss the AXF yet. Use the power of SQL that it wields! I would change your function to something like:
Function ReturnNextID(tbl, strFieldName)  'tbl = tblName/layerName
Dim intMax
Dim ds
Dim query
Dim qRows
Set ds = Map.Layers("CityTrees").DataSource  'Assuming layerName = CityTrees
query = "SELECT max(" & strFieldName & ") FROM " & tbl
Set qRows = ds.execute(query)     'Execute Query
qrows.movefirst        'Read results
intMax = qRows.fields(1).value
ReturnNextID = intMax + 1
End Function
0 Kudos