Hi! I want to concatenate information from a same field but different records.
So I took a sample I found and tried to make it more generic by adding more arguments, but it seems like not working.
Can you take a look at it and see if you find any error? When I execute the function in a query, it appears a popup: "Error 3265: any element was found on this collection" (translated from Spanish)
It highlights strText = "" & RS!strField
So I took a sample I found and tried to make it more generic by adding more arguments, but it seems like not working.
Can you take a look at it and see if you find any error? When I execute the function in a query, it appears a popup: "Error 3265: any element was found on this collection" (translated from Spanish)
Code:
Option Compare Database
Option Explicit
Public Function fConcatenate(intID As Integer, strField As String, strTble As String)
Dim strSQL1 As String
Dim strSQL2 As String
strSQL1 = "SELECT " & intID & ", " & strField
strSQL2 = "FROM " & strTble
Dim strSQL As String
Dim strText As String
strSQL = strSQL1 & " " & strSQL2
'Open a Recordset and loop through it to fill the text box txtTest with
'the faults Repaired >>>reprorted by the customer<<<<
Dim db As DAO.Database
Dim RS As DAO.Recordset
Set db = CurrentDb
Set RS = db.OpenRecordset(strSQL, dbOpenForwardOnly)
Do Until RS.EOF
If strText = "" Then 'This If statment prevents a single comma at the begining of the text","
strText = "" & RS!strField
Else
strText = strText & ", " & RS!strField
End If
RS.MoveNext
Loop
RS.Close
Set RS = Nothing
Set db = Nothing
Let fConcatenate = strText
End Function
It highlights strText = "" & RS!strField