DConcat function - Concatenating field values for multiple records matching a query's GROUP / SORT BY or WHERE clause
You can use SQL to sum/average/find the min or max of values for data that you're grouped using a GROUP BY query in Microsoft Access. Alternatively you could use the less efficient built-in domain functions. Wouldn't it be nice if you could concatenate text fields in a similar manner.
The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.X Object Library or Microsoft Office 16.0 Access database engine Object Library (use the most recent version). To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the appropriate Object Library reference check box is selected. Also, it uses the IsTableQuery() function.
So the idea is to take data like this:
Band | Member |
---|---|
Metallica | James Hetfield |
Metallica | Kirk Hammett |
Metallica | Lars Ulrich |
Metallica | Robert Trujillo |
The Beatles | John Lennon |
The Beatles | Paul McCartney |
The Beatles | George Harrison |
The Beatles | Ringo Starr |
And turn it into this:
Band | Members |
---|---|
Metallica | James Hetfield, Kirk Hammett, Lars Ulrich, Robert Trujillo |
The Beatles | John Lennon, Paul McCartney, George Harrison, Ringo Starr |