Results 1 to 4 of 4

Thread: autonumber vba

  1. #1
    Join Date
    Feb 2004
    Posts
    24

    Angry Unanswered: autonumber vba

    Hi
    I am trying to execute a insert statement through VBA. One of the columns in my table is autonumber. How do you get the next value?


    for example.

    insert into table members member_id, member_name values ( xxxx, "Bob")

    what would I put in place of --- xxxx ---?

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,423
    Provided Answers: 8
    If the Table has been setup right the autoumber will look after its self.
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Feb 2004
    Posts
    24
    I am not sure what you mean.


    what would I put for values?

    for example.

    insert into table members member_id, member_name values ( xxxx, "Bob")


    where -- xxxx -- is the autonumber

  4. #4
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Do you need to get the value to use somewhere else, or are you concerned about it assigning the correct number?

    Autonumber fields will not let you assign data to them - they will assign data to themselves automatically.

    In other words, when you insert a new record, the autonumber field will automatically increment to the next number (hence the name).

    Replace
    Code:
    insert into table members member_id, member_name values ( xxxx, "Bob")
    with
    Code:
    insert into table members member_name values ( "Bob")
    As a matter of fact, even if you cancel the transaction, the number that was assigned is still "used up" - the next time you insert data, you'll get the NEXT number. This is because Access assigns the "autonumber" as soon as a record is initiated, just in case multiple users are in there at the same time.

    Have fun

Posting Permissions

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