473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Autonumber (number sequencing) Via Query

I realize this has been covered a billion times, I've read them all and still can't get it. My table looks like this:
DOCUMENT-SER.NO
MC006343 -SST-24569
MC006344 -SST-27209
MC006344 -SST-27210
MC006397 -SST-25019
MC006397 -SST-24562
MC006397 -SST-24562
MC006397 -SST-99173
MC006397 -SST-99173

DOCUMENT-SER.NO.-NEED THIS
MC006343 -SST-24569-0001
MC006344 -SST-27209-0001
MC006344 -SST-27210-0002
MC006397 -SST-25019-0001
MC006397 -SST-24562-0002
MC006397 -SST-24562-0003
MC006397 -SST-99173-0004
MC006397 -SST-99173-0005

At every change in Document Number, start the numbering over.

Using an Update Query, I need to update a field (named LINE) showing the numbers in the "NEED THIS" column above. 0001, 0001, 0002, 0001, 0002, 0003, 0004, 0005...etc.

This would give me a different line number for each document...

I've read all the autonumber and dmax posts, and still can't get it.
NOVICE Access User...can use queries pretty good, but not SQL.

MSAccess 2003, Windows XP Pro...

Thanks in advance!
Jul 31 '08 #1
2 1700
I'm sure there is a more elegant way to do this, but I've done this by breaking the task into a sequence of queries.

Query 1:
Create Table TEMP_TABLE (
[DOCUMENT-SER-NO] Text(50),
Document Text(50),
rowid AutoIncrement,
sequence integer
);

Query 2:
INSERT INTO TEMP_TABLE ( Document, [DOCUMENT-SER-NO] )
SELECT Left([DOCUMENT-SER-NO],InStr([DOCUMENT-SER-NO]," ")-1) AS doc, BaseTable.[DOCUMENT-SER-NO]
FROM BaseTable
ORDER BY Left([DOCUMENT-SER-NO],InStr([DOCUMENT-SER-NO]," ")-1), BaseTable.[DOCUMENT-SER-NO];

Query 3:
SELECT TEMP_TABLE.Document, Min(TEMP_TABLE.rowid) AS MinOfrowid INTO MinList
FROM TEMP_TABLE
GROUP BY TEMP_TABLE.Document;

Query 4:

UPDATE MinList INNER JOIN TEMP_TABLE ON MinList.Document = TEMP_TABLE.Document SET TEMP_TABLE.sequence = [rowid]-[MinOfRowid]+1;

Now, Table [TEMP_TABLE] looks like:

DOCUMENT-SER-NO Document rowid sequence
MC006343 -SST-24569 MC006343 1 1
MC006344 -SST-27209 MC006344 2 1
MC006344 -SST-27210 MC006344 3 2
MC006397 -SST-24562 MC006397 4 1
MC006397 -SST-24562 MC006397 5 2
MC006397 -SST-25019 MC006397 6 3
MC006397 -SST-99173 MC006397 7 4
MC006397 -SST-99173 MC006397 8 5

Then, you can either do an update query or whatever you need to using this new table. Your new document ID is
Trim([DOCUMENT-SER-No]) & "-" & Format([sequence],"0000")

If you want to add drop table queries to your sequence, they would look like:

drop table [MinList];

drop table [TEMP_TABLE];
Aug 1 '08 #2
Thanks...this works fine.
Thanks for the clairity...I've been reading all the autonumber posts and they were just making me crazy.

Thanks again
Aug 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: deko | last post by:
Is there a way to reset the AutoNumber sequence? I have several tables that use the AutoNumber field as the Primary Key, and I'd like to somehow do an Import/Export that will make remove the...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
2
by: junkaccount | last post by:
Hello, I currently have a field named QuoteNumber in a table named Quotes. The field is set as autonumber and is used to assign sequential numbers as users enter information in the table through...
3
by: rdemyan | last post by:
I have a table that is imported from another system. I have no choice but to use the data as is; they will not change it. The records are not unique. For reasons I don't want to get into, I...
6
by: PeteCresswell | last post by:
Got a table with "RecordID"=AutoNumber=PrimaryKey. Call it "tblIssuerRating". Ran a query that appends to that table from a work table. Inadvertantly appended from the work table's...
5
by: john | last post by:
A record of a table with an autonumber field was accidentally deleted. From the backup table I made a new table with only the deleted record. Then with an add query I added that record to the...
6
by: Wayne | last post by:
I'm using the following SQL statement to find the next highest autonumber value in a table where "CDUGActID is the autonumber field in the "CDUGActuals" table: SELECT CDUGActuals.CDUGActID,...
6
by: ashes | last post by:
Hi, I am creating an ecommerce website using Microsoft Visual Studio, VB.Net and MS Access 2003. I am new to VB.Net When someone wants to register on the website, they fill out a form and the...
1
by: lawitt | last post by:
I have a MakeTable query whose resulting table i'm using in a crosstab query. The fields in the crosstab are constantly changing (weekly), so my ultimate goal has been to somehow create a dynamic...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.