Question : using a query to combine multiple records into one record

Hi,

I have two tables. [TblProject] is set up with the following fields:
ProjectID (AutoNumber)
ProjectName (Text)
ActiveProject (Yes/No)

and this table has a one to many relationship with a table called [TblPersonnel] which has the following:
PersonnelID (AutoNumber)
ProjectID (Relation to TblProject - ProjectID)
PersonnelName (Text)

I want to run a SQL query which shows each record in TblProject once and if there are multiple entries in TblPersonnel then have them concentated into one field. Or put another way, instead of the query showing
[ProjectID]      [ProjectName]      [ActiveProject]     [Personnel]
       1                   Name A                  Yes             Personnel 1
       1                   Name A                  Yes             Personnel 2
       1                   Name A                  Yes             Personnel 3
       2                   Name B                    No              Personnel 2

To be shown as:
[ProjectID]      [ProjectName]      [ActiveProject]     [Personnel]
       1                   Name A                  Yes             Personnel 1, Personnel 2, Personnel 3
       2                   Name B                    No              Personnel 2

Sorry, I know next to nothing about writing SQL queries so any help will be much appreciated

Answer : using a query to combine multiple records into one record

Is there a reasonable limit to the number of people within a project? That is, can you state some number for which there will never be more people on a project than that number?

I think the easiest thing is to create a public function to do this concatenation. You pass the projectID to the function and the function returns the concatenated personnel as a string.
Example:
1:
2:
3:
4:
5:
6:
7:
8:
9:
Public Function ConcatField(parmID As Long) As String
  Dim rs As Recordset
  Dim strConcat As String
  Set rs = Currentdb.OpenRecordset("Select PersonnelName From TblProject Where ProjectID = " & parmID )
  Do Until rs.EOF
    strConcat = strConcat & rs!PersonnelName & ", "
  Loop
  ConcatField = Left(strConcat, Len(strConcat)-2)
End Function
Random Solutions  
 
programming4us programming4us