Access (VBA) to create unique ID numbers for alike records

Experts:

I need some assistance with (potentially) a VBA function that **adds a unique ID number** to records.   If records are alike (based on various demographics), the same new ID number must be replicated.

In other words, qryTable1 should be turned into a "Make Table" (and using the VBA function) and then add **8 records** with each alike record (based on [Name] and [Age] to the **new ID" field.   Alternatively, qryTable2 should be turned into a "Make Table" (and using the VBA function) and then add **9 records** with each alike record (based on [Name] and [Age] and [Ethnicity] to the **new ID" field.

As a picture is worth a thousand words, I believe (hope) the additional information in the spreadsheet provides sufficient information.

Thank you in advance,
EEH
Example-Data.xlsx
Example-Data.accdb
ExpExchHelpAnalystAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You can use my RowNumber function in my article here:

Sequential Rows in Microsoft Access

It will create a row number for each unique combo of fields, say: [Name] & CStr([Age])

Please note, that a demo is for download.
ExpExchHelpAnalystAuthor Commented:
Gustav:

Thank you for the prompt response.   I downloaded your zipped demo file... wow, I'm not entirely certain how to translate your code into my basic table.

Attached is my attempt using your function RowNumber...

In my case, Query 1 produces 8 records while Query 2 produces 9 records.

Somehow though, I would like all 12 records (either in the existing table or a new table) to have the "ID" number.  

How would this have to be accomplished in my sample database (see attached)?

EEH
Example-Data-with-Gustavs-Module.accdb
Gustav BrockCIOCommented:
It could be:

SELECT 
    RowNumber([FirstName] & CStr([Age])) AS ID, 
    [01_tblExample].FirstName, 
    [01_tblExample].Age, 
    [01_tblExample].Ethnicity
FROM 
    01_tblExample
WHERE 
    RowNumber([FirstName] & CStr([Age])) <> RowNumber("","",True)
ORDER BY 
    [01_tblExample].FirstName, 
    [01_tblExample].Age, 
    [01_tblExample].Ethnicity;

Open in new window

EEno.PNGNote, there is an error in the recording of Ages for Michaels.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Fabrice LambertConsultingCommented:
the same new ID number must be replicated.
Erm .....
 that does not make sens to begin with!!

IDs are usually used as primary keys, so they must be unique.
Unless you're speaking about a foreign key, but in that case, you should name it accordingly.
ExpExchHelpAnalystAuthor Commented:
Gustav -- your solution works perfectly... in fact, it worked better than anticipated once I plugged it into my actual data set.  

Thousand thanks!!

EEH
ExpExchHelpAnalystAuthor Commented:
Gustov -- you provided the perfect solution.   Thank you very much for your assistance in this matter.

EEH
Gustav BrockCIOCommented:
You are welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.