Dim yRow As Long, rstClone As Recordset
Dim oldRegion As String, oldCIN As String, oldID As Long, oldRate As Long, tempCounter As Long, changeCount As Long
Set rstClone = CurrentDb.OpenRecordset("NameOfTable").Clone
tempCounter = 1
changeCount = 0 ' Keeps a track of how many fields are unique. If there at least then increment counter, else set counter to 1
With rstClone
If .BOF = False Then
If MsgBox("Backup your table before continuing" & vbCrLf & "Continue?", vbYesNo) = vbYes Then
' Fill the recordset
.MoveLast
.MoveFirst
For yRow = 0 To .RecordCount - 1
If ((!Region & "") = oldRegion) Then
changeCount = IIf((!CIN & "") = oldCIN, changeCount + 1)
changeCount = IIf(!ID = oldID, changeCount + 1)
changeCount = IIf(!Rate = oldRate, changeCount + 1)
If changeCount < 2 Then
tempCounter = 1
End If
Else
tempCounter = 1
End If
' Update the counter field
.Edit
!counter = tempCounter
.Update
' Save the values for checking against the next record
oldRegion = !Region
oldCIN = !CIN
oldID = !ID
oldRate = !Rate
' Increment tempCounter
tempCounter = tempCounter + 1
' Reset changeCount
changeCount = 0
.MoveNext
Next
MsgBox "Finished updating."
End If
Else
MsgBox "There are no records"
End If
End With