English

How To: Create a sequential unique ID field equivalent to the ArcView 3.x field calculator expression rec+1

Summary

In ArcView 3.x, typing 'rec+1' in the field calculator creates a sequential unique ID field for a layer. Instructions provided describe how to do the equivalent in the ArcMap field calculator.

Procedure

  1. Add the number field.

    A. Click Options in the table where the field will be added.
    B. Click Add Field.
    C. Type the name of the field.
    D. Click the Type dropdown arrow and specify the numeric field type.
    E. Set any other field properties.
    F. Click OK.

  2. Click Start Editing on the Editor toolbar.
  3. Right-click the new number field. Click Calculate Values.
  4. Click the Advanced check box.
  5. Copy the following code into the Pre Logic VBA Script code:

    Code:
    Static rec As Long
    Dim pStart As Long
    Dim pInterval As Long

    ' adjust start value if you want it to
    ' start at a value other than 1.
    ' For example, 1000.
    ' ====================================

    pStart = 1

    ' adjust interval value if you want it to
    ' increment at a value other than 1.
    ' For example, 2.
    ' =======================================

    pInterval = 1

    If (rec = 0) Then
    rec = pStart
    Else
    rec = rec + pInterval
    End If

  6. Type the word 'rec' in the text box under [Your Field Name] =.
  7. Click OK.

Related Information