Bonjour,
Je cherche à concaténer (si j'puis dire) le même champ sur différents enregistrements ayant un facteur commun (Client).
J’ai donc une requête, ou une table, avec une colonne CLIENT et une autre GERANT, exemple :
Client / Gerant
A / Annie
A / Doudou Galak
A / Rene
B / Toto
B / Sylvie
B / Marc
Je souhaiterais obtenir une table ou une requête avec les enregistrements suivants :
Client / Gerant
A / Annie - Doudou Galak – Rene
B / Toto – Sylvie - Marc
La requête : SELECT tbl_Client.Client, tbl_Client.Gerant,
ConcanEnQuery("Client",[Client],
"[Gerant]","tbl_Client"," - ") AS Gestion
FROM tbl_Client
ORDER BY tbl_Client.Client;
Le code dans un module :
Function ConcanEnQuery(strRegroup As String, fldRegroup As String, _
strConcat As String, strTable As String, _
Optional strSepar As String = "/") As String
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strResulta As String
Dim strRst As String
Set db = CurrentDb()
strRst = "Select * From [" & strTable & "] " _
& "Where [" & strRegroup & "] = """ & fldRegroup & """;"
Set rst = db.OpenRecordset(strRst, dbOpenDynaset)
With rst
If Not .BOF Then
.MoveFirst
Do Until .EOF
If strResulta = "" Then
strResulta = .Fields(strConcat)
Else
strResulta = strResulta & strSepar & .Fields(strConcat)
End If
.MoveNext
Loop
End If
End With
rst.Close: Set rst = Nothing
db.Close: Set db = Nothing
ConcanEnQuery = strResulta
End Function
Cordialement.
__________________________
Le peu que je sais, c'est à mon ignorance que je le dois. Sacha Guitry