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

Incrementing counter and record deletion 1

Status
Not open for further replies.

sbeltyukov

Technical User
Jan 24, 2007
8
0
0
US
Hi,

The user wants all of the records in the database to have continuous numbering. I have used AutoNumber in the past but if you delete a record, it produces gaps in the numbering. I was wondering if there is a way to number the records so they are always numbered continuously (1, 2, 3, etc.) even if some record is deleted.

I have tried using the following:

Code:
Set db = CurrentDb()
Set recordlist = db.Openrecordset("SELECT Max(tblContactHistory.ItemID) AS MaxID FROM tblContactHistory")

ItemID = (recordlist!MaxID + 1)

recordlist.Close
Set recordlist = Nothing

but I still cannot get the records to have continuous numbering after a record is deleted.


Any helped would be appreciated.

Thanks!
 
What do you expect to happen if a number/record is deleted from the middle? Do you want all records renumbered at that time?

Ask your "user" if they have a good reason for consecutive numbering. You can always generate this type of value in a ranking query.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I see your point. I contacted them and they said that gaps are fine. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top