Question : Access 2002 concatenating records into one field

Is there anyway to group several text records into one record and insert a line feed between them.

For example, lets say I have the following records:
John AAA
John BBB
John CCC
John DDD
Bill ZZZ
Bill YYY
Bill XXX

I would like one record with one long field to contain AAA _ BBB _ CCC _ DDD where the underscore represents some sort of line feed so the data appears on different lines on the report.

Answer : Access 2002 concatenating records into one field

johnfaig,

Sure, but because you did not post an *actual* example of the expected output, ...to me it just looks like you want to have something like this:
AAA
BBB
CCC
DDD
ZZZ
YYY
XXX

This is what I can only glean from:


If so then it looks like all you need to do is trim off everything to the left of the space.

Try something like this:

Dim rst As DAO.Recordset
Dim strNewText As String

Set rst = CurrentDb.OpenRecordset("tblData")

    rst.MoveFirst
   
    Do While Not rst.EOF
        strNewText = strNewText & vbCrLf & Right(rst!Data, Len(rst!Data) - InStr(rst!Data, " "))
        rst.MoveNext
    Loop
   
    strNewText = Right(strNewText, Len(strNewText) - 2)
   
    Me.txtNewText = strNewText

'Cleanup
rst.Close
Set rst = Nothing



Here is a sample.

I am sure you can adapt this to work in your database.

;-)

Jeffcoachman
Random Solutions  
 
programming4us programming4us