Access Sequential numbering

Barry NP

New Member
Joined
Jul 18, 2017
Messages
23
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.
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,935
Office Version
  1. 2019
Platform
  1. Windows
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.
 

Barry NP

New Member
Joined
Jul 18, 2017
Messages
23
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.
 

JonXL

Active Member
Joined
Feb 5, 2018
Messages
369
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Do you need to do this for records already in the DB or just for new ones?
 

Barry NP

New Member
Joined
Jul 18, 2017
Messages
23
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.
 

JonXL

Active Member
Joined
Feb 5, 2018
Messages
369
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,114,116
Messages
5,546,030
Members
410,721
Latest member
adi772
Top