Results 1 to 10 of 10

Thread: Access Autonumber

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Access Autonumber

    Hi guys, i have some troubles with my database, i really need your help.

    Let say i have a table with 10 records in it with an autonumber from 1 to 10. Now i want to insert a new record and i want make that record the second line.

    So the point is increase record from 10 to 11, 9 to 10... and so on.. cause i don't want duplicate.

    I already done this with VB6. It works however for some reason sometimes it doesn't.

    My question is "Is there any way to do it automatically with Access". Increase auto from the insert record.

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access Autonumber

    If it is actually an AutoNumber, it should be done automatically within Access already.

    So, what is it that you are currently doing? (and what data type is the field)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: Access Autonumber

    yes, it's a text field. The autonumber works however the new insert record will be 11 in this case (after the 10 ligne already there). This is not what i want, i want that the new record will be appear as 2 and the existing records from 2 will increase to 3 + and so on.

    I am able to do it with VB6 without the autonumber of access, but it's not stable.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access Autonumber

    Why is it a Text field?

    Being a Number would make sense, but even that would still not be ideal.
    I am able to do it with VB6 without the autonumber of access, but it's not stable.
    It will probably never be stable (or safe), especially if it is going to be used by multiple people.

    Why are you avoiding the built-in method (which has already been designed to cover the issues you are having and more, and is fully tested)?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: Access Autonumber

    sorry for my draw talent.
    Attached Images Attached Images  

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access Autonumber

    I'm afraid I have no idea what you meant by that - please try to explain in words what is 'wrong' with using an AutoNumber.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: Access Autonumber

    If i try
    vb Code:
    1. .Execute ("Insert Into * Table (Field) VALUES ('" & mytext & "')")

    Then to autonumber will increase from the last record.


    This is not what i want. i want to the new insert ligne have the number 2. and the existing record increase one by one. Hope it's clear enought. Thnaks for your help

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Access Autonumber

    It still isn't clear I'm afraid.. after reading that a few times, I think you might mean that you want to add a new record in the "middle" of the existing values, and increment all of the existing ones (eg: [1, 2, 3, 4] would become [1, new, 2+1 =3, 3+1=4, 4+1=5] ).

    Is that correct?

    And if so, why do you want to do that?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    230

    Re: Access Autonumber

    yes, that's correct.

  10. #10
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Access Autonumber

    You'd have to do that manually, something along the lines of
    Code:
    UPDATE yourTable SET yourNumberField = yourNumberField + 1
    WHERE yourNumberField >= newNumberToInsert
    You'd have to do this before inserting the new record, because otherwise you won't update the previous existing number.
    Tengo mas preguntas que contestas

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