What does "wasn't having any luck with that" mean - error message, wrong result, nothing happens? Allen's code should be able to accommodate your requirement.
There is no criteria in your SQL so of course every record will return the same result.
Need a function that receives input as arguments (see AB or thedbGuy code).
I doubt calling function from an event procedure will be satisfactory. Call function in query or textbox.
Be aware this kind of procedure can cause slow performance in query/form with large dataset.
What is the SQL used for form RecordSource? Possibly presentation in a form is not best option, maybe should be a report.
Provide sample of raw data tables. Build tables in post or attach file (db or Excel).
I did a test using the first dataset in OP as source for form and function. Called function in textbox with:
Code:
=ConcatRelated("Defendants","Data","ItemDescription & Format(DateDelivered,'yyyymmdd')='" & [ItemDescription] & Format([DateDelivered],"yyyymmdd") & "'","","; ")
(and if you want output to be alphabetic order, use "Defendants" in function ORDER BY argument)
In query:
Code:
SELECT Data.ItemDescription, Data.DateDelivered, Data.Defendants,
ConcatRelated("Defendants","Data","ItemDescription & Format(DateDelivered,'yyyymmdd')='" & [ItemDescription] & Format([DateDelivered],"yyyymmdd") & "'","Defendants","; ") AS Defs
FROM Data;
ItemDescription |
DateDelivered |
Defendants |
Defs |
Book |
|
Smith, Joe |
Smith, Joe |
Book |
1/1/2024 |
Blith, Ian |
Blith, Ian; Hull, John |
Book |
1/1/2024 |
Hull, John |
Blith, Ian; Hull, John |
Book |
2/1/2024 |
Kart, Ryan |
Gull, Megan; Kart, Ryan; Pon, Mary |
Book |
2/1/2024 |
Pon, Mary |
Gull, Megan; Kart, Ryan; Pon, Mary |
Book |
2/1/2024 |
Gull, Megan |
Gull, Megan; Kart, Ryan; Pon, Mary |
Pencil |
|
Blith, Ian |
Blith, Ian; Hull, John; Smith, Joe |
Pencil |
|
Hull, John |
Blith, Ian; Hull, John; Smith, Joe |
Pencil |
|
Smith, Joe |
Blith, Ian; Hull, John; Smith, Joe |
Pencil |
3/1/2024 |
Kart, Ryan |
Gull, Megan; Kart, Ryan; Pon, Mary |
Pencil |
3/1/2024 |
Pon, Mary |
Gull, Megan; Kart, Ryan; Pon, Mary |
Pencil |
3/1/2024 |
Gull, Megan |
Gull, Megan; Kart, Ryan; Pon, Mary |