By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,617 Members | 1,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,617 IT Pros & Developers. It's quick & easy.

Build string variable

P: n/a
I have code that loops through a record set, which build an outlook
email's body. The problem is, I don't know how to "build" the .body
while in the loop without resetting the .body's value to the current
record.

For example, the .body should equal:
John
Jake
Debby

So, .body = .body & vbCrlf & (previously looped value).body

Any suggestions?

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Soundneedle wrote:
I have code that loops through a record set, which build an outlook
email's body. The problem is, I don't know how to "build" the .body
while in the loop without resetting the .body's value to the current
record.

For example, the .body should equal:
John
Jake
Debby

So, .body = .body & vbCrlf & (previously looped value).body

Any suggestions?


You're already including the previous loop value by putting the .body in the
expression on the right of the = sign. Just remove everything after the vbCrLf.

In the first loop .body will be set to John plus a line feed. In the second it
will be set to itself (this retains John) and then has Jake and another line
feed added. After three loops you should have all three names.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

P: n/a
"Soundneedle" <so*********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I have code that loops through a record set, which build an outlook
email's body. The problem is, I don't know how to "build" the .body
while in the loop without resetting the .body's value to the current
record.

For example, the .body should equal:
John
Jake
Debby

So, .body = .body & vbCrlf & (previously looped value).body

Any suggestions?


Rather than changing the actual body each time you run through the loop,
just change a variable and once all looping is finished, assign the body.
So assuming the field is called FirstName and that it cannot be null:

Dim strBody As String

While Not rst.EOF
strBody = strBody & vbCrLf & rst.Fields("FirstName")
rst.MoveNext
Wend

..Body = strBody

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.