Using Access 2000
The code below is supposed to pull a field called [CreditTo], from a one-field query, [qryMemTest], and put the data together in a string.
Say there are 3 records in the query - Jack Apple, Sam Bright and Sarah Candle. I want to put them in a report so that they will appear like this...
Jack Apple, Sam Bright, Sarah Candle
So I put an unbound text box in the Detail section of the report that has the expression...
The function always produces an error on the line
Set rst = dbs.OpenRecordset(strSQL)
even though when I put the cursor on strSQL it shows the correct result.
Obviously, I am doing something wrong.
Any suggestions as to how to fix this would be appreciated.
Thanks.
Tom
The code below is supposed to pull a field called [CreditTo], from a one-field query, [qryMemTest], and put the data together in a string.
Code:
Function Concat2(aRSet As String, _
aField As String) As String
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strRes As String
strSQL = "SELECT [" & aField & "] FROM [" & aRSet & "]"
Set dbs = CurrentDb
[b]Set rst = dbs.OpenRecordset(strSQL)[/b]
While Not rst.EOF
strRes = strRes & ", " & rst(aField)
rst.MoveNext
Wend
If strRes <> "" Then
strRes = Mid$(strRes, 3)
End If
Concat2 = strRes
rst.Close
Set rst = Nothing
Set dbs = Nothing
End Function
Say there are 3 records in the query - Jack Apple, Sam Bright and Sarah Candle. I want to put them in a report so that they will appear like this...
Jack Apple, Sam Bright, Sarah Candle
So I put an unbound text box in the Detail section of the report that has the expression...
Code:
=Concat2("qryMemTest","CreditTo")
The function always produces an error on the line
Set rst = dbs.OpenRecordset(strSQL)
even though when I put the cursor on strSQL it shows the correct result.
Obviously, I am doing something wrong.
Any suggestions as to how to fix this would be appreciated.
Thanks.
Tom