CDO Message - I want to send more than one line in my email message.

Posted on 2006-04-21
Last Modified: 2008-02-01
I have tried several different ways to send more than just the details of my message.  Below is what I want to do but isn't working.  If I replace all the .TextBody lines with just  .TextBody = Request1.Details.Text  the code works fine.  But the minute I try to get more complicated my .ASP page won't display because there is an error.  How do I get the multiple lines of the TextBody to be displayed in my email?

Set cdoMessage = Server.CreateObject("CDO.Message")
    On Error Resume Next
    With cdoMessage
        Set .Configuration = cdoConfig
        .Fields("urn:schemas:httpmail:importance").Value = 2
        .From = Requests1.EmailAddr.Text
        .To = ""
        .Subject = "New IT Request"
        .TextBody = "Date/Time: " & Request1.ReqDate.Text & Chr(10) & Chr(13)
        .TextBody = .TextBody & "Requestor: " & Request1.Requestor.Text
        .TextBody = .TextBody & "     Phone: " & Request1.Phone.Text & Chr(10) & Chr(13) & chr(10) & chr(13)
        .TextBody = .TextBody & "Priority: " ReqPriority
        .TextBody = .TextBody & "     Request Type: " & Request1.ReqType.Text
        .TextBody = .TextBody & "     Category: " & Request1.Category.Text & Chr(10) & Chr(13) & chr(10) & chr(13)
        .TextBody = .TextBody & Request1.Details.Text

    End With
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    On Error Goto 0
Question by:terrydschmidt
    LVL 4

    Expert Comment

    what is the error?

    try building textBody in a string

    strText = this & chr(10) & chr(13) & that etc ...

    .textbody = strText

    Author Comment

    I just tried this   .TextBody = "Test:" & Request1.Details.Text    and I get a blank message but NO error.  
    This is in an .asp file on my webpage.
    So, I tried .TextBody = "Test:"  and that works.  Test: shows in my email message.

    I tried:
    Dim txtBody

    txtBody = "Test"

    .txtBody = txtBody

    I got Test in my email message but if I did:  .txtBody = txtBody & Request1.Details.Text  I got a blank message.  It seems like an & is not working.  My visual basic is rusty how do I create a string without ampersans?

    Author Comment

    OK, ampersan is not the problem it's when I combine quoted text and a variable.

    txtBody = "Hi there" & vbNewLine & vbNewLine & _
            "This is line 1" & vbNewLine & _
            "This is line 2" & vbNewLine & _
            "This is line 3" & vbNewLine & _
            "This is line 4"

    above works - my email message shows all the text.

    txtBody = "Hi there" & vbNewLine & vbNewLine & _
            "This is line 1" & vbNewLine & _
            "This is line 2" & vbNewLine & _
            "This is line 3" & vbNewLine & _
            "This is line 4" & Request1.Details.Text

    above does not work.  I get a blank email message.
    LVL 4

    Expert Comment

    you're in uncharted territory for me, but what about something like

    strHold = request1.details.text

    txtbody = ... & vbNewLine & "This is line 4" & strHold


    Author Comment

    I think I found my error. Request1.Details.Text is suppose to be Requests1.Details.Text  (see the s between the t and the 1 it helps when it there).  I now broke my send so I am not getting any emails to test.  I get back to you when I figure what I broke.


    Author Comment

    I answered my own question above.  Thanks!

    Accepted Solution

    PAQed with points refunded (125)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now