Library code snippets

Access AutoNumber Reset

This is some sample code that shows how to programmatically reset all AutoNumber fields in an Access Database to a correct value (whether it be 0 or the max value + 1). In addition, it contains code for Compacting and Repairing an MS Access Database. This is perfect for people who are working with a complicated Access Database and have experienced AutoNumber bugs!

Comments

  1. 16 Oct 2008 at 01:56
    Wow. Thanx. I hope this moves me over, and I will be able to make deep table clones with relations. If not, compacting and repairing is great step forward for [Light DB Browser](http://quilt.ic.cz/tmp/upl/Soft.htm#ldb)
  2. 23 Jun 2007 at 10:11

    Hi only new to access so I am not sure I am doing the right thing.

    When I run this I point it to my Database & run it. It goes through everything and completes successfully. But I cannot see any changes.

    All my autonumbers are still the same they have not been reset starting from one.

    What am I doing wrong or have I got it wrong and this is not what its suppost to do.

    Pls let me know.

    Tks

  3. 01 Jun 2007 at 18:26
    I agree with the others that the little autonum reset application is very nice however I've been banging my head over trying to use it with a db that has a username and password.  It looks obvious but I can't seem to get it to work.
    When I plug in 2 variables:
    UserID = "Admin"
    Password = "MYPASSWORD"
    I get this error:
    "Cannot start application. The workgroup information file is missing or opened exlusively by another user."
    The database is not open at all so I don't understand what the problem is.
    I am a newbie to this so I'm thinking that I must be making some silly mistake. I was hoping that you wouldn't mind pointing me in the right direction. What am I doing wrong?

    PS ... if I disable the password in my db, your application works like a charm.
    Thanks in advance.













  4. 02 Feb 2007 at 20:25
    Thanks a lot!! This is a very useful application!! WELL DONE!

    Dejan



  5. 23 Sep 2005 at 16:28
    I have been having the problem with autonumber reset for the past couple of months, and I am getting tired of having to delete the relationships, create a new table, copy the data etc... Can this reset program of your's work in Access 2003, or are there additional steps I am not completing?  I get the following error message "There has been a critical error! Error - 2147467259 Method '-' object '-' failed"

    Thank you in advance for your assistance.
  6. 10 Sep 2005 at 04:13

    The code is part of a Visual Basic project (VB6).  It uses an external ADO connection into Access in order to do the autonumber reset.  You can do the same thing inside of access by adding a reference to ADO in the Visual Basic editor, then editing the code to work inside an Access module.

  7. 09 Sep 2005 at 17:10

    I have access database that use autonumber (starting from 1) , I have some number that is missing, how do I reset it?
    Sorry, I am not a programmer, so I didn't understand where I should put the code .


    Thank you very much
    clee

  8. 01 Jun 2005 at 09:48
    nice

    changed a line in your module code:

    sExt = Right$(sDestination, Len(sDestination) - InStrRev(sDestination, ".") + 1)
  9. 11 Sep 2003 at 02:35

    Well Done Mike....just what I needed! Saves re-building the database...whcih was what I'd been told by 'the experts' at our place!

  10. 01 Jan 1999 at 00:00

    This thread is for discussions of Access AutoNumber Reset.

Leave a comment

Sign in or Join us (it's free).

Mike Gagne Current Occupation: consultant; Degrees: BS-Computer Science, BS-Mathematics, Japanese minor; Known Languages: C#, ASP.NET, WPF, PHP, SQL, C++, VB

Want to stay in touch with what's going on? Follow us on twitter!