Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I actually decided to post this as an answer instead of a comment to make it more easily accessible.</p> <p>What you want is exactly what other DBMS's provide (which I don't really like to use) that is called <code>GROUP_CONCAT</code>. I edited your title to make that more apparent to future searchers(hope you don't mind).</p> <p>Since Access doesn't support <code>GROUP_CONCAT</code> in SQL syntax, you could either write some funky SQL to hope to replicate it or just use VBA.</p> <p>Below is an example <code>GROUP CONCAT</code> VBA function that you can use. found <a href="http://blogannath.blogspot.com/2011/01/microsoft-access-tips-tricks-flattening_28.html" rel="nofollow">here</a> (I didn't write it).</p> <pre><code> Function Concatenate(pstrSQL As String, _ Optional pstrDelim As String = ", ", _ Optional pstrLastDelim As String = "") _ As Variant ' Created by Duane Hookom, 2003 ' this code may be included in any application/mdb providing ' this statement is left intact ' example ' tblFamily with FamID as numeric primary key ' tblFamMem with FamID, FirstName, DOB,... ' return a comma separated list of FirstNames ' for a FamID ' John, Mary, Susan ' ======= in a Query ========================= ' SELECT FamID, ' Concatenate("SELECT FirstName FROM tblFamMem ' WHERE FamID =" &amp; [FamID]) as FirstNames ' FROM tblFamily ' ============================================ ' to get a return like Duane, Laura, Jake, and Chelsey ' ======= in a Query ========================= ' SELECT FamID, ' Concatenate("SELECT FirstName FROM tblFamMem ' WHERE FamID =" &amp; [FamID], ",",", and ") as FirstNames ' FROM tblFamily ' ============================================ ' If FamID is a string rather than numeric, ' it will need to be delimited with quotes ' ======= in a Query ========================= ' SELECT FamID, ' Concatenate("SELECT FirstName FROM tblFamMem ' WHERE FamID =""" &amp; [FamID] &amp; """", ",",", and ") as FirstNames ' FROM tblFamily ' ============================================ '======For DAO uncomment next 4 lines======= '====== comment out ADO below ======= Dim db As DAO.Database Dim rs As DAO.Recordset Set db = CurrentDb Set rs = db.OpenRecordset(pstrSQL) '======For ADO uncomment next two lines===== '====== comment out DAO above ====== 'Dim rs As New ADODB.Recordset 'length before last concatenation Dim intLenB4Last As Integer 'rs.Open pstrSQL, CurrentProject.Connection, _ adOpenKeyset, adLockOptimistic Dim strConcat As String 'build return string With rs If Not .EOF Then .MoveFirst Do While Not .EOF intLenB4Last = Len(strConcat) strConcat = strConcat &amp; _ .Fields(0) &amp; pstrDelim .MoveNext Loop End If .Close End With Set rs = Nothing '====== uncomment next line for DAO ======== Set db = Nothing If Len(strConcat) &gt; 0 Then strConcat = Left(strConcat, _ Len(strConcat) - Len(pstrDelim)) If Len(pstrLastDelim) &gt; 0 Then strConcat = Left(strConcat, _ intLenB4Last - Len(pstrDelim) - 1) _ &amp; pstrLastDelim &amp; Mid(strConcat, intLenB4Last + 1) End If End If If Len(strConcat) &gt; 0 Then Concatenate = strConcat Else Concatenate = Null End If End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload