View Full Version : How to reset primary key to zero


constantG
06-24-2009, 12:30 PM
Hi,

I wish to be able to reset a primary key to zero as and when required. That's all, it probably is very simple, but I cannot find the answer anywhere.

Thank you,

C W

David Eagar
06-24-2009, 12:38 PM
To the best of my knowledge, delete ALL entries from ALL tables and then do a compact and repair

constantG
06-24-2009, 01:02 PM
Thanks for the speedy reply. That method would render my database useless unfortunately.

constantG
06-24-2009, 01:11 PM
I think I should try to explain my database, so here goes.

I am in the Navy and when my vessel goes to sea each person receives telegrams from family and friends. Each gram must be sequentially numbered and distributed. I have the autonumber feature assigned to ensure that when the grams are logged on the database, the number increases by 1. It is this function that I wish to reset at the start of every trip. Is this possible via a macro or other?

All help gratefully received.

Thank you.

C W

I should also say that if this database works out for me, I would wish to distribute it to other vessels, so the automation of this task would be desirabe.

SOS
06-24-2009, 01:43 PM
You can just delete all of the data from that ONE table and then do a compact and repair and it will reset.

constantG
06-24-2009, 01:52 PM
You can just delete all of the data from that ONE table and then do a compact and repair and it will reset.

Ahhh I see, now all I need to know is how to automate this through a button on the main page in my database. I should mention that I am unfamiliar with VB and use only macros in my database.

Thanks SOS :D

SOS
06-24-2009, 01:54 PM
Code for the Button:


CurrentDb.Execute "DELETE * FROM YourTableName", dbFailOnError


And you can then do the compact. See here (http://www.btabdevelopment.com/main/CodeSnippets/CompactDatabase/tabid/122/Default.aspx) for ways to compact programmatically.

constantG
06-24-2009, 02:41 PM
Thanks very much SOS. I will have a read.

C W

SOS
06-24-2009, 02:43 PM
Good luck - And also to you and all of your shipmates -

THANK YOU for serving. I have the utmost admiration for those in the Armed Services who have to deal with the "not so good" things that can happen around the world.

David Eagar
06-24-2009, 03:12 PM
If you want to keep records of the telegrams, you would need to copy to a history table before you delete

SOS
06-24-2009, 03:18 PM
If you want to keep records of the telegrams, you would need to copy to a history table before you delete
Good point - thanks for mentioning it as it might be important given the initial response to your other post.

gemma-the-husky
06-25-2009, 05:01 AM
you dont really need to delete the old messages

simply have a trip identifier in the message table, then you can find the total weight for any given trip

constantG
06-25-2009, 09:00 AM
you dont really need to delete the old messages

simply have a trip identifier in the message table, then you can find the total weight for any given trip
That's a good idea. Now to figure out how to do it.

Thanks for all your assistance.

C W