Results 1 to 6 of 6
  1. #1
    knightjp is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2008
    Posts
    11

    Renumbering

    I made a table with one autonumber primary key and one rank.
    I would like a way that when I select delete button on a form to delete a record, it will move the one below up and renumber the rank in ascending order...



    I've attached a rough database table showing how the data is supposed to look

  2. #2
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    I think you forgot to attach your table.

    No! Never change the primary key of a row.

    Rank on the other hand is another matter. Assuming your rank is numeric, what you need to do is build a recordset in ascending rank order. Then using an incrementing counter go through the recordset row by row updating the rank to be that of the counter and incrementing the counter.

    This may be somewhat inefficient if the number of rows is large and/or deletions are frequent. You could employ techniques to jump to the row immediately before the deletion and rerank from there on and/or delay the reranking until all deletions have occurred.

  3. #3
    knightjp is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2008
    Posts
    11
    Thanks Rod for the reply.
    The truth of the matter is that when I take a report out, the numbering is left with gaps... my renumbering this was just so that the list numbers on the report would be left in sequence.
    I found an easy of doing this without any coding, etc....

    http://allenbrowne.com/casu-10.html

  4. #4
    Rod is offline Expert
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Location
    Metro Manila, Philippines
    Posts
    679
    If you sourced from Allen Browne you could do no better!

  5. #5
    knightjp is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2008
    Posts
    11
    Quote Originally Posted by Rod View Post
    If you sourced from Allen Browne you could do no better!
    Seriously?! The site is that good???

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    It's seriously that good. It stares at me from my bookmarks toolbar all the time.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Renumbering Auto-Increment numbers
    By svcghost in forum Database Design
    Replies: 8
    Last Post: 02-19-2011, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums