Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can i change the autonumber with code? 1

Status
Not open for further replies.

primerov

Technical User
Aug 16, 2002
160
BG
How can i change the autonumber in a table with a function? I want to make my autonumber of the field OrderID of the table
Orders to begin from 7000 instead from 1.Is there any function with ADO or DAO ?
Thank you for the help
 
Autonumber fields are difficult to manipulate and deleted numbers cannot be recovered. If you need control of your ID field then you should consider using a Long Integer and creating a function to update the field in the Before_Update() event of the form or setting the field's default value to a function such as:

Default Value: =DMax("[field]","
") + 1


Then you can manually add 7000 for the first record and the rest will increment naturally.

If you absolutely have to have an autonumber field then just use a query to insert 6999 phony records and then use another query to delete them. Since Access never reuses a deleted autonumber, the next record will start at 7000.

VBSlammer
redinvader3walking.gif
 
Might not be relevant to your application, but just in case: if a table containing autonumber fields is empty and the database is compacted then the autonumber is reset.


Must think of a witty signature
 
Another thing to note... Using an auto number is not a good idea in general for any data that a user will see... I would suggest making a table that has only one record, and only one colum... then use a recordset to add one to that and then use that number... The reason I suggest this is that as DarenNM said if you compact the database, all auto numbers will then see the current highest number and use the next one higher. Not good when working with any kind of customer data because then you may have two cusomers with the same id, one that's old and been removed, then the number may be reused do to a compact... the same would happen using a dmax funtion as said above by VBslammer... This is a fine thing if it is for programming use only, but for use as user viewable data, I think that's a bad idea...

Just my thoughts, and I'm sorry for the bad grammer and spelling... I'm just in a little of a rush here:)

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top