Select to view content in your preferred language

Populate 2 Attributes based on one Value

1935
1
06-24-2010 03:44 PM
AndrewHansford
Frequent Contributor
Hi All,

I am working on a project in ArcPad 8 SP3.

I have a Shapefile with to fields

  1. UserNumber (Long Integer)

  2. UserText3 (Text Field)


Below is my Code that i have created to autogenerate a Unique ID and my Text_box that it relates to will store that value that is returned to UserNumber. How would I go about adding that value directly to the Attribute table for UserText3?

 

Sub InitialiseGPSID
'Do any form initialization in this sub
 Dim objEFPageOneControls, objEditForm
 Set objEditForm = ThisEvent.Object 
 Set objEFPageOneControls = objEditForm.Pages("PAGE1").Controls
  
 'Initialization for form in any mode
 'Disable the GPS ID edit box

  objEFPageOneControls("txt_GPSID").Enabled = False


  'Initialization for form when adding new records

  If objEditForm.Mode = 3 Then ' Mode 3 is used when creating a new feature.
    

    'Get the Fence Points layer's recordset (to pass into the ReturnNextID function)
    Dim objUniqueID

    Set objUniqueID = Layer.Records

 if ReturnNextID (objUniqueID, "USERNUMBER") = 1 then
    'Update the Tree ID
     objEFPageOneControls("txt_GPSID").Value = ReturnNextID (objUniqueID, "USERNUMBER") + 10000
 else
  objEFPageOneControls("txt_GPSID").Value = ReturnNextID (objUniqueID, "USERNUMBER")
 end if

  End If
  'Free objects
  Set objEFPageOneControls = Nothing
  Set objEditForm = Nothing
  Set objUniqueID = Nothing
End Sub

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'Also write the function ReturnNextID that is called by InitializeForm. 
 
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


'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Tags (3)
0 Kudos
1 Reply
AndrewHansford
Frequent Contributor
I figured out a quick and easy solution:

Sub InitialiseGPSID
'Do any form initialization in this sub
 Dim objEFPageOneControls, objEditForm
 Set objEditForm = ThisEvent.Object 
 Set objEFPageOneControls = objEditForm.Pages("PAGE1").Controls
  
 'Initialization for form in any mode
 'Disable the GPS ID edit box

  objEFPageOneControls("txt_GPSID").Enabled = False


  'Initialization for form when adding new records

  If objEditForm.Mode = 3 Then ' Mode 3 is used when creating a new feature.
    

    'Get the Fence Points layer's recordset (to pass into the ReturnNextID function)
    Dim objUniqueID

    Set objUniqueID = Layer.Records

 if ReturnNextID (objUniqueID, "USERNUMBER") = 1 then
    'Update the Tree ID
     objEFPageOneControls("txt_GPSID").Value = ReturnNextID (objUniqueID, "USERNUMBER") + 10000
 objEFPageOneControls("txt_AssetID").Value = ReturnNextID (objUniqueID, "USERNUMBER") + 10000
 else
  objEFPageOneControls("txt_GPSID").Value = ReturnNextID (objUniqueID, "USERNUMBER")
  objEFPageOneControls("txt_AssetID").Value = ReturnNextID (objUniqueID, "USERNUMBER")
 end if

  End If
  'Free objects
  Set objEFPageOneControls = Nothing
  Set objEditForm = Nothing
  Set objUniqueID = Nothing
End Sub

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'Also write the function ReturnNextID that is called by InitializeForm. 
 
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


'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


The text in the yellow links to a invisible text box in the form then saves the value to the field in the Shapefile.

not a clear work around but does for now.

Cheers
0 Kudos