1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Function ConcatForQuery(strRegroup As String, fldRegroup As String, _
strConcat As String, strTable As String, _
Optional strSep As String = "/") As String
'** Regroupement de donnée sur le champ fldRegroup
'** et concaténation sur le champ strConcat
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strResult As String
Dim strRst As String
Set db = CurrentDb()
strRst = "Select * From [" & strTable & "] " _
& "Where [" & strRegroup & "] = """ & fldRegroup & """;"
Set rst = db.OpenRecordset(strRst, dbOpenDynaset)
With rst
Do Until rst.EOF
If strResult = "" Then
strResult = Nz(.Fields(strConcat), "")
ElseIf Nz(.Fields(strConcat), "") <> "" Then
strResult = strResult & strSep & .Fields(strConcat)
End If
.MoveNext
Loop
End If
End With
rst.Close: Set rst = Nothing
db.Close: Set db = Nothing
ConcatForQuery = strResult
End Function |
Partager