Solved

Access Table - Add Field To Auto Number Records, Resetting When Record Value Changes

Posted on 2013-01-25
3
817 Views
Last Modified: 2013-01-25
I have a table with a column of Item Numbers sorted by the item number.
I am tying to find a way to insert a column to number the records based on the item number.
For example,

Counter      Item Number
1                   AAA
2                   AAA
3                   AAA
4                   AAA
5                   AAA
1                   BBB
2                   BBB
3                   BBB
1                   CCC
2                   CCC
3                   CCC
4                   CCC
5                   CCC
etc.

Any help would be appreciated.
0
Comment
Question by:Scamquist
3 Comments
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 350 total points
ID: 38819488
you can do that in a query



select a.*, (select count(*) from tblData B where B.itemnumber=a.itemnumber and b.id >=a.id) as counter
from tblData as A
order by a.itemnumber
0
 
LVL 77

Assisted Solution

by:peter57r
peter57r earned 150 total points
ID: 38819554
To do this, you must have an autonumber ID field already present in the table (or some other unique field which provides a defined sort sequence).  So if you don't have one you must add one.

Then a query such as the one posted by Cap1 will number like records in a query.
Unless you have a further reason for doing so, there is no real need to update the table with this sequence value.
0
 
LVL 1

Author Closing Comment

by:Scamquist
ID: 38819663
Thank you both.  Capricorn1 had the right formula.  However, I did not have an ID field, so it was failing.  Added the ID (peter57r) and all was well with the world.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question