Hi everyone,

I am facing a very unique problem. I have written a code for auto incrementing of registration numbers. The auto increment takes place when the form loads or the record is added.

Now the problem is after 13810 records the code is refusing to auto increment. The records are getting added, but with the number 13810. Can u guys please suggest what is causing this out of the blue error?


Code:
Public Sub Autogenregest()
On Error Resume Next
Dim a As Long, b As String

If rs1.State = 1 Then rs1.Close
rs1.Open "clientprofile", con, adOpenDynamic, adLockOptimistic
If rs1.BOF = True And rs1.EOF = True Then
    brs.Open "Backup", con, adOpenDynamic, adLockOptimistic
  a = Val(brs(0).Value)
    brs.Close
    
    b = "C" & a
    TxtRegNo.Text = b
Else

     rs1.MoveLast
    a = Val(Right(rs1(0).Value, Len(rs1(0).Value) - 1) + 1)
      
     b = "C" & a
    
    TxtRegNo.Text = b
End If
End Sub
Regards,
Kaushik