Ok i found this Automated unique sequential ID field script that works great for creating sequential unique id's but i need it to generate on a click event. I need it to generate the unique sequential Id when i click on a button the button that populates certain fields.
Another issue is that i need it to update a string filed (Address_ID; CC1234) not just a numeric field.
Here is the code i found and working with.
Option Explicit
Private m_bPopulate As Boolean
Private m_EditEventChange As Boolean
Private WithEvents m_pEditEvents As Editor
Private Function MxDocument_OpenDocument() As Boolean
Dim pEditor As IEditor
Dim pUID As New UID
pUID = "esriCore.Editor"
Set pEditor = Application.FindExtensionByCLSID(pUID)
If pEditor Is Nothing Then
MsgBox "Unable to Enable UIC Custom Editing Environment", vbOKOnly, "ERROR...UIC Editing Environment"
Exit Function
End If
Set m_pEditEvents = pEditor
m_bPopulate = True
m_EditEventChange = False
MsgBox "Edit Event Field Population is Enabled", vbOKOnly, "AGRC Custom Editing..."
End Function
Private Sub m_pEditEvents_OnCreateFeature(ByVal obj As esriGeoDatabase.IObject)
'Creates new ID number for new feature
Dim pRow As IRow
Dim newIDIndex As Integer
Dim pTable As ITable
Dim pCursor As ICursor
Dim pData As IDataStatistics
Dim pStatResults As IStatisticsResults
Dim IDMax As Variant
Dim NewID As Long
Dim changeMade As Boolean
Set pRow = obj
If Not m_bPopulate Then Exit Sub
'Find index (as long) of "ID_NUMBER" field
newIDIndex = pRow.Fields.FindField("AddresID_2")
'Set up cursor
Set pTable = obj.Table
Set pCursor = pTable.Search(Nothing, False)
'Set up statistics parameters
Set pData = New DataStatistics
pData.Field = "AddresID_2"
Set pData.Cursor = pCursor
'Find the max value of the "ID_NUMBER" field
Set pStatResults = pData.Statistics
IDMax = pStatResults.Maximum
'Add 1 to create next (sequential)ID number
NewID = IDMax + 1
changeMade = False
If newIDIndex > 0 Then
pRow.Value(newIDIndex) = NewID
changeMade = True
End If
If changeMade Then
m_EditEventChange = True
pRow.Store
End If
m_EditEventChange = False
End Sub