解決方案是使用訪問模塊中的VBA代碼來將重複值「串在一起」(在您的案例中爲「數字」)。代碼的一般形式是:
Option Compare Database
Option Explicit
Public Function ListChildNames(ParentID As Long) As String
Dim cdb As DAO.Database, rst As DAO.Recordset, rtn As String
Const separator = "; "
Set cdb = CurrentDb
Set rst = cdb.OpenRecordset(_
"SELECT [ChildName] FROM [ChildTable] " & _
"WHERE ID=" & ParentID, _
dbOpenSnapshot)
rtn = ""
Do While Not rst.EOF
rtn = rtn & rst![ChildName] & separator
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set cdb = Nothing
If Len(rtn) > 0 Then
rtn = Left(rtn, Len(rtn) - Len(separator)) '' trim trailing separator
End If
ListChildNames = rtn
End Function
(你將不得不調整表和列名,以配合您的表結構。)
然後,在記錄源爲您的報告,而不是使用...
SELECT [Name], [Number] ... FROM ...
...你會使用類似...
SELECT [Name], ListChildNames([Name]) AS Numbers ... FROM ...
...檢索[名稱]和單行中的(連接列表)[Number]值。
謝謝。你的方法有效。 – Chris 2013-05-14 12:42:19