Results 1 to 9 of 9

Thread: Auto Increment of records not taking place?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    76

    Auto Increment of records not taking place?

    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

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Auto Increment of records not taking place?

    Try removing the "On Error Resume Next" all that is doing is ignoring errors.

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Auto Increment of records not taking place?

    what does this
    Code:
    rs1(0).Value
    contain?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2005
    Posts
    76

    Re: Auto Increment of records not taking place?

    Quote Originally Posted by Doogle
    Try removing the "On Error Resume Next" all that is doing is ignoring errors.
    Hi,

    Thanks for the suggestion, but still no sign of any error messages

    regards,
    Kaushik

  5. #5
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Auto Increment of records not taking place?

    add a long variable and keep incrementing it with each pass of record in rs. have a if statement when the value reaches 13810, set a break point here. Now go step by step using F8, hover mouse over each variable value, you should be finding the error.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Auto Increment of records not taking place?

    You are assuming that the last record in the table has the largest Registration Number. That's not necessarily the case. Have you actually examined the complete table ?
    If you used an SQL statement like
    Code:
    SELECT * FROM clientprofile ORDER BY <whatever the column name is for the Registration number>
    in the rs1.Open statement then when you execute rs1.MoveLast you will be at the record having the largest Registration Number

  7. #7
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Auto Increment of records not taking place?

    Doogle is correct. Your attempt should be to check the largest value of number in rs1(0) than simply moving to the last record. The fact that largest no. will be found in the last row might only be true for a autonumber field (in your case it is not).
    Last edited by VBFnewcomer; Dec 20th, 2007 at 07:20 AM. Reason: added 'be'

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Auto Increment of records not taking place?

    And implementation is not for a multiuser environment.

    TxtRegNo.Text = b

    With that code, more than one user can retrieve your ID.

  9. #9
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Auto Increment of records not taking place?

    Why not just set your ID type to AutoNumber ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width