Access Sequential numbering

Barry NP

New Member
Joined
Jul 18, 2017
Messages
24
Hi all,
Appreciate any help with my query.
I am developing an access dtb to record Accidents, Incidents and Near Misses. I have a table named SHE_Database. This has ID as the primary key and a field called Record_Type and another field called Reference.

What I am trying to do is potentially use the DMax function to increment a unique reference number for each record by not using the ID field.
So if the very first record - ID 1 - is recorded as an ACCIDENT in the 'Record_Type' field, then I want the 'Reference' field to show as ACC-0001, and then sequentially after that for each record recorded as ACCIDENT, so the second ACCIDENT record recorded will show ACC-0002 and so on.

If the second record - ID 2 - is recorded as an INCIDENTin the 'Record_Type' field , I want the 'Reference' field to show as INC-0001, and then sequentially after that for each record recorded as INCIDENT, so the second INCIDENT recorded will show as INC-0002 and so on.

The same for NEAR MISS.

Is this possible with the DMAX function, or is there another way of doing this?
Any help would be greatly appreciated.

Thanks.
Barry.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Why do you think this type of unique ID is necessary. If for filtering, then you could filter on the Record Type in a query. It seems to me that you are over complicating your needs when you can have an autonumber in the ID field as a unique identifier and can filter on the Record Type.
 
Upvote 0
Why do you think this type of unique ID is necessary. If for filtering, then you could filter on the Record Type in a query. It seems to me that you are over complicating your needs when you can have an autonumber in the ID field as a unique identifier and can filter on the Record Type.

Hi Alansidman. Many thanks for your repoky and I had pointed this out, however this is a request from out Health and safety Department that each record recorded as an Accident, Incident or Near Miss starts at 1, so that we have ACC-0001, INC-0001 and NMR-0001 (for near miss), incrementing by 1 for each new record.
 
Upvote 0
Do you need to do this for records already in the DB or just for new ones?
 
Upvote 0
Do you need to do this for records already in the DB or just for new ones?

Hi JonXL. This is a new database so there is only one record in the database as a test record so this would be for all new records from record ID2 if that makes sense? I have seen posts about DMax() function but I must be missing something as I haven't yet got this to work!! Any help much appreciated.
Thanks
Barry.
 
Upvote 0
To do this in just the one table, I would create a field for the counter and you can set the next counter on the record's creation using DMax() + 1 with the criteria limiting to only those record with the same type as that of the record you are adding. If you need specifics beyond that, we'll need to know more things about your setup such as how users are getting data into the table, etc.

Once you have the counter if you want to store the concatenated type and counter number in a separate field, you can do that, but it'd also be easy enough to just create this at run time when needed.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,163
Members
448,554
Latest member
Gleisner2

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