Sequential Numbering in a Query

giddyup43

New Member
Joined
Dec 3, 2015
Messages
29
Hi.
I tried googling this for a while but I can't figure it out.
I am importing multiple tables from a few different people, and need to assign a unique, sequential sku code to each record and add it to a main, combined table.
So person A is sending me a table with 100 records and all sku's are 0, (its primary key is an autonumber field). I need to reference the last sku in the main table, (example, 32,126) and number all these records incrementally starting from 32,127. Then, i will add these records to the main table.
Person B is also sending me a table with 100 records and all sku's are 0, and I need the sku's to start from 32,227 (the last sku now in the main table).
I believe I have to use the dmax function but I haven't figured out how to do it in a query for multiple records. Most forums just explained how to do it in a form.
If someone could help me with this, I would really appreciate it.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
is 32,126 the autonumber field? Probably not but need to confirm. Also, is there a reason why you could not append all of the records from everybody, sans sku's, to the main table and then update the missing value? Regardless of whether or not they can be done in a batch or table by table, I think you're stuck with a code solution. Unless you update a single tblA record based on tblMain.Sku + 1 THEN immediately copy that record to tblMain, I don't see how you can recursively get the next sku from tblMain since not copying the record over leaves the sku constant. That is to say, a calculated field in an update query where newSku = old+1, old plus one is a constant.

It wouldn't be too hard to update a recordset on a table, or at least repetitively execute an update query in a code loop by assigning Max(tlbMain.sku) to a variable, then updating that variable via a counter that increments by one upon each iteration. It would be more efficient to do that in one swoop rather than on each person's table.
 
Last edited:
Upvote 0
When you say you import someone else's data, what does that mean? Do you bring it into a temp table in your database? Put it right in your main table? Are their any relevant fields besides sku (i.e., primary key fields or other key fields?).
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top