Hi All,
Allen Browne posted the following code in 1998 regarding Concatenating
a string a text from a table into a report.
I want to do something similar. I have a query that returns email
addresses based on some selections made within a form.
I would like to have a txt field on the form that returns the emails
from the query as a single string of text. For example:
bob@hotmail; john@hotmail; frank@hotmail... etc
This is the code that was originally posted and discussed here:
http://groups.google.com.au/group/comp.databases.ms-access/browse_thre...thread/
------QUOTE-------
The function assumes:
1. There is a table that stores the related records you want to
concatenate.
Replace "MyTable" in the function with the actual table name.
2. That table has a foreign key that relates it to the table the
report is
based on.
3. That foreign key field is numeric. Replace "MyForeignKey" in the
function
with the actual field name.
4. Replace "MyField" in the function with the name of the field you
wish to
read. (2 occurances.)
You can then create a text box on your report to display the results.
Make sure this text box's Name is different from any field in your
report's
recordset, and set its ControlSource property to:
=ShowRelated([xxxxxx])
where "xxxxxx" represents the primary key of the report's recordset.
-------------------------------------------------------
Function ShowRelated(vID) As String
'Purpose: Return a single string of all the related records.
Dim db As Database
Dim sSQL As String
Dim rst As Recordset
Dim sOut As String
Dim iLen As Integer
Const SEP = ", " ' The separator between records.
If IsNumeric(vID) Then ' If it's not Null etc.
sSQL = "SELECT MyField FROM MyTable WHERE MyForeignKey = " &
vID &
";"
Set db = CurrentDb()
Set rst = db.OpenRecordset(sSQL)
Do While Not rst.EOF
sOut = sOut & rst![MyField] & SEP
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
iLen = Len(sOut) - Len(SEP)
If iLen > 0 Then
ShowRelated = Left$(sOut, iLen) 'remove trailing
separator.
End If
End If
End Function
-----END QUOTE-----
I have tried to modify this code however I can't seem to get it to
work for me. I think its all coming under around the ForeignKey
crietera which I don't have in my situation.
Has anyone else attempted something similar?
My Query is called "qry_Form_Invitees" and the column I want to
concatenate is "tbl_Bankers.Email" or just 'Email' on the sourse Table