Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2013
    Posts
    12

    Arrow Unanswered: Auto generate ID number

    Hi! I'm quite new with VBA in access.. Can anyone help to auto generate an ID number? I've tried the following codes, but when I add a new record the ID number does not appear at all...


    Private Sub StudID_BeforeUpdate(Cancel As Integer)
    Dim tot As Integer
    tot = 0
    tot = tot + 1
    StudID = S + tot
    End Sub


    Thanks in advance!

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Make the field in the table an "AutoNumber" field and it will do this for you without any extra code.
    George
    Home | Blog

  3. #3
    Join Date
    Jun 2013
    Posts
    12
    That's true, but I need the Id number to start with an alphabet.. :/

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off id use a function that returned a value
    in that function you'de need to find the current maximum value
    then add one to that value and return the value

    the step you are missing is that at no point do you find what the current maximum value is.
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Create an autonumber field.

    Then create a query over that table with a column that appends the "S" to the AutoNumber.
    Simply reference the query from there on.

    You really don't need a character at the beginning. It is unnecessary.
    George
    Home | Blog

Posting Permissions

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