مثال در سایت زیر دقیق بخوانید و اجرا کنید ( هر آنچه نمی دانید را در google سرچ کرده و با یادگیری از اکسس لذت ببرید
Concatenate-Column-Values-from-Multiple-Rows-into-a-Single-Column-with-Access
مثالی دیگر
Public Function ConcatRelated(strField As String, _ strTable As String, _ Optional strWhere As String, _ Optional strOrderBy As String, _ Optional strSeparator = ", ") As Variant
Dim rs As DAO.Recordset
Dim rsMV As DAO.Recordset
'Multi-valued field recordset
Dim strSql As String
SQL statement'
Dim strOut As String
Output string to concatenate to'
Dim lngLen As Long
Length of string'
Dim bIsMultiValue As Boolean
Flag if strField is a multi-valued field'
Initialize to Null'
ConcatRelated = Null
(Set rs = DBEngine(0)(0).OpenRecordset(strSql, dbOpenDynaset
(Determine if the requested field is multi-valued (Type is above 100'
(bIsMultiValue = (rs(0).Type > 100
Do While Not rs.EOF
If bIsMultiValue Then
For multi-valued field, loop through the values'
Set rsMV = rs(0).Value
Do While Not rsMV.EOF
If Not IsNull(rsMV(0)) Then
strOut = strOut & rsMV(0) & strSeparator
End If
rsMV.MoveNext
Loop
Set rsMV = Nothing
ElseIf Not IsNull(rs(0)) Then
strOut = strOut & rs(0) & strSeparator
End If
rs.MoveNext
Loop
rs.Close
Clean up'
Set rsMV = Nothing
Set rs = Nothing
Exit Function
For the example above, you could set the ControlSource of a text box to
=
"ConcatRelated("OrderDate", "tblOrders","CompanyID
[CompanyID] &
or in a query:
"SELECT CompanyName, ConcatRelated("OrderDate
([tblOrders", "CompanyID = " & [CompanyID",
FROM tblCompany