MajP
You've got your good things, and you've got mine.
- Local time
- Today, 17:02
- Joined
- May 21, 2018
- Messages
- 9,947
Just understand Allen Browne's function, my original function, and ArnelGp's solution are really all the same. Just slightly different aproaches to creating the recordset, but they are still creating a new recordset in each call to the function. There is IMO no way to use the actual reports recordset, I do not think a report even exposes a recordset property.
My final solution is however different in that I open the recordset and leave it open, instead of continously opening and closing a recorset. This is faster than opening and closing on each function call.
When the report loads it creates a recordset based off the reports recordsource, and leaves it open. Then each call to the concatenate does not have to create a new recordset.
However, speed is relative. I used @arnelgp solution on the large report and it was a few seconds slower, but still not bad for 500 groups. It this was thousands of groups it would make a difference.
My final solution is however different in that I open the recordset and leave it open, instead of continously opening and closing a recorset. This is faster than opening and closing on each function call.
Code:
Private rs As DAO.Recordset
Private Sub Report_Load()
Set rs = CurrentDb.OpenRecordset(Me.RecordSource, dbOpenDynaset)
End Sub
Private Function ConcatName(GroupID As Integer) As String
'Exit Function
rs.FindFirst "groupID = " & GroupID
Do While Not rs.NoMatch
If ConcatName = "" Then
ConcatName = rs!Full_Name
Else
ConcatName = ConcatName & "; " & rs!Full_Name
End If
rs.FindNext "groupID = " & GroupID
Loop
End Function
When the report loads it creates a recordset based off the reports recordsource, and leaves it open. Then each call to the concatenate does not have to create a new recordset.
However, speed is relative. I used @arnelgp solution on the large report and it was a few seconds slower, but still not bad for 500 groups. It this was thousands of groups it would make a difference.