Automatic email with multiple lines

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AllusiveKitten
    New Member
    • Feb 2007
    • 43

    Automatic email with multiple lines

    Hi all

    I am trying to set up an automatic email that requires multiple lines and paragraphs.

    Can someone please help me, the coding I have so far only sustains one continuous line.

    Code:
    Private Sub Command0_Click()
     
    Dim Email As String
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem
     
    Email = "name@company.com"
     
    Set objOutlook = CreateObject("Outlook.application")
     
    Set objEmail = objOutlook.CreateItem(olMailItem)
     
    With objEmail
        
        .To = Email
        .Subject = "Test email document"
        .Body = "This is just a test"
        .Send
    End With
     
    Set objEmail = Nothing
     
    End Sub
    Thank you for your help
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    You inadvertently posted your question in the Access Articles section. I have moved it across for you to the main forum.

    MODERATOR

    Comment

    • Jim Doherty
      Recognized Expert Contributor
      • Aug 2007
      • 897

      #3
      Originally posted by AllusiveKitten
      Hi all

      I am trying to set up an automatic email that requires multiple lines and paragraphs.

      Can someone please help me, the coding I have so far only sustains one continuous line.

      Code:
      Private Sub Command0_Click()
       
      Dim Email As String
      Dim objOutlook As Outlook.Application
      Dim objEmail As Outlook.MailItem
       
      Email = "name@company.com"
       
      Set objOutlook = CreateObject("Outlook.application")
       
      Set objEmail = objOutlook.CreateItem(olMailItem)
       
      With objEmail
       
      .To = Email
      .Subject = "Test email document"
      .Body = "This is just a test"
      .Send
      End With
       
      Set objEmail = Nothing
       
      End Sub
      Thank you for your help

      Concatenate your message into a string variable and then assign the variable to the BODY as below demonstrates:

      Code:
       Dim mymsg as string 
      mymsg = "This is just a test & vbcrlf
      mymsg = mymsg & "This is another line" & vbcrlf
      mymsg = mymsg & "This is yet another line & vbcrlf & vbcrlf
      mymsg = mymsg & "This line has double spaced" 
      	.Body = mymsg
      .Send
      Regards

      Jim

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32668

        #4
        Notice the vbCRLF that's used in Jim's code. This is a Carriage Return / Line Feed sequence which essentially means a new line.
        That is how it is done :)

        Comment

        • AllusiveKitten
          New Member
          • Feb 2007
          • 43

          #5
          Thank you both, you are a great help.
          Thank you NeoPa for clarifying the meanings.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32668

            #6
            No problem AK - Glad to help :)

            Comment

            Working...