Creating a string from a recordset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to open a recordset and get the data and put into a string so I
can post it as a text message. Where each record will return under the last
record

I dont know how to build a string by cycling through the records. I'm know
I use a loop of some sort but I do not know how to make it work.

Query results. Philip |26 |02/16/73 |Male
Jan |24 |05/15/69 |Female

Post in a string:
Philip, 26, 02/16/73, Male
Jan, 24, 05/15/69, Female
 
You can open recordset, then loop through it and concatenate fields like
this:

strResult=strResult & rst("Name") & ", " & rst("Age") & " ," & .... 'list
all other fields like this
'then add new line
strResult = strResult & vbcrlf

at the end of the loop strResult will contain what you want
 
With ADO Recordset, you can also use GetString Method to get all rows in a
string.

If rst is the recordset, then use:

rst.GetString(adClipString, , ";", vbCrLf)

If you use MsgBox rst.GetString(adClipString, , ";", vbCrLf) to view, then

the messageBox will display

Philip;26;|02/16/73;Male
Jan;24;05/15/69;Female
 
Back
Top