Here is the function that returns a String of employees allocated to a Section:
Public Function findPrep(st As String)
' This function returns a String of all staff members allocated to a section
' in the Responsibility Assignment Matrix.
Dim rs As Recordset
Dim qd As QueryDef
Dim qrySt, stRet, stSQL, prosID, Sect As String
Dim fld As Fields
prosID = Forms![Tender]![ProspectID] 'ProspectID
'Sect = Forms![Tender_RAM]![Sect] 'Section
Sect = st
'create an SQL string for the query
Set qd = CurrentDb.QueryDefs("prep")
qd.Parameters("Prospect") = prosID
qd.Parameters("sec") = Sect
Set rs = qd.OpenRecordset
rs.FindFirst "[Tender_RAM_Prep].[Sect] = '" & Sect & "'"
If Not rs.EOF Then
'base case
Set fld = rs.Fields
stRet = fld(2)
rs.MoveNext
While Not rs.EOF 'terminating case
stRet = stRet & ", " & fld(2) 'add a comma, then add next name
rs.MoveNext 'move to next
Wend
End If
findPrep = stRet
End Function
Here is the SQL for the query that uses the function:
SELECT Tender_RAM.ProspectID, Tender_RAM.Sect AS [Section], Tender_RAM.Desc AS Description, findPrep([Sect]) AS [Responsibility for Prep], Tender_RAM.Prep_Due AS [Prep Due], findSign([Sect]) AS [Responsibility for Signoff], Tender_RAM.Signoff_Due AS [Signoff Due]
FROM Tender_RAM
WHERE (((Tender_RAM.ProspectID)=[Forms]![Tender]![Text274]));
I only pasted one of the functions above, there is another one called findSign() which is very similiar, and just lists people allocated for signing off on a job.
Keep in mind also that this listbox is on a subform, which may also be affecting it.
Thanks for all the replies.
Ben