Build string variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Soundneedle

    #1

    Build string variable

    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?

  • Rick Brandt

    #2
    Re: Build string variable

    Soundneedle wrote:[color=blue]
    > 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?[/color]

    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


    Comment

    • Justin Hoffman

      #3
      Re: Build string variable

      "Soundneedl e" <soundneedle@ho tmail.com> wrote in message
      news:1113351916 .839254.61940@o 13g2000cwo.goog legroups.com...[color=blue]
      >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?[/color]

      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("Fir stName")
      rst.MoveNext
      Wend

      ..Body = strBody



      Comment

      Working...