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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I seed an Autonumber to start at a certain number?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
Basically, I want a table, with an Autonumber Primary key, but instead of starting at 1, I want to start at 25000 or something like that.
 
I don't think there is a way to get the AutoNumber to start at 25000 -- but you could build a calculated field in a query that adds 25000 to your autonumber.

For instance if your autonumber field was called TestID

Your calculated field could be an expression like:
ID : [TestID] + 25000
Hope this helps
Thanks
Tim
 
If you are trying to do this to a new table, it's pretty simple. Create your table and before you enter any data into the table, use an insert query to add the first record to the table.

Like so:

INSERT INTO TableName (autonumber) VALUES (25000);

This will create a record with the value you used as the autonumber field. Subsequent records will increment from the number you chose. Mind you, this only will work once on a newly created table.

HTH,
Will
 
Thanks Ymesei, I used that route. Tho I am going to have to remember about calculated fields Chesterex1. But Ymesei, I tried it, realized I wanted a different number, and did it again to the same table. So you can use that method over and over. You can even do it on a table with data. It simply makes the next autonumbered record start from your seed.

HTH, and Thanx!
 
You ought to read Michael Red's faq700-184 to get further background on autonumber and search this forum for other posts on autonumber (there are many). There are strong feelings about autonumber on all sides of the issue and you should at least be aware of what is being said.
 
Interesting. I had originally a table with 1 row. This row contained a number. My app would read the number and replace it with an incremented value. Problem was I began getting duplicate order numbers. Yuck. Maybe I should learn how to do a better lock on the table via .Net.
 
qwert,

Your right. I realize now that you can change the autonumber to a higher number, but not a lower number. For example if your autonumber is at 12000 and you want to reset to a lower number, you can't just delete all the existing records and lower the autonumber.

Will
 
That is true. I have been doing some experimenting with it.

Hey, why are all my users banging on my door with bats and broom handl4 ijnt6
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top