Results 1 to 5 of 5
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095

    Formatting Body string for multiple lines using CDO mail

    How do I configure my "strBody" line when there are multiple lines? I've tried strBody = "Line1" & chr(10) & "Line2" & chr(10) & "Line3" etc, but the linefeed doesn't take effect. I just get the string "Line1" & chr(10) & "Line2" & chr(10) & "Line3" in the resulting email.

    Here's the code:
    Code:
    Public Function UnPak(TxtFile As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  User has several txt files, some of which are multiple lines. UnPack the files into
    '  a single string suitable for insertion into the subject or body parameters for CDO
    '  emailing.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strInLine As String
    Const strNewLine As String = " & chr(10) &"
    UnPak = ""
    
    
    Open TxtFile For Input As #1
    Line Input #1, strInLine
    If EOF(1) Then
        UnPak = strInLine
    Else
        While Not EOF(1)
            UnPak = UnPak & """" & strInLine & """" & strNewLine
            Line Input #1, strInLine
        Wend
        UnPak = Left(UnPak, Len(UnPak) - Len(strNewLine))
    End If
    
    
    Close #1
    
    
    End Function


  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Have you thought about vbCRLF ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Yes, and I get this:
    "Good morning Bill," & vbCRLF &"Attached is today's Summerset Table Menu." & vbCRLF &"Have a blessed day."

    I mean in the body of the email.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You need either:

    vbCrLf

    or
    (yes, the order shown matters)
    Chr(13) & Chr(10)

    Show how you use vbCrLf. It should not be within quote marks.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    2,095
    Revised code works fine, thank you Welshgasman & June.

    Code:
    Public Function UnPak(TxtFile As String) As String
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    '  User has several txt files, some of which are multiple lines. UnPack the files into
    '  a single string suitable for insertion into the subject or body parameters for CDO
    '  emailing.
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
    Dim strInLine As String
    UnPak = ""
    
    
    Open TxtFile For Input As #1
    Line Input #1, strInLine
    If EOF(1) Then
        UnPak = strInLine
    Else
        While Not EOF(1)
            UnPak = UnPak & strInLine & vbCrLf
            Line Input #1, strInLine
        Wend
    End If
    
    
    Close #1
    
    
    End Function

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Using CDO to email HTML content in the body of the email
    By GraeagleBill in forum Programming
    Replies: 3
    Last Post: 03-20-2025, 11:26 AM
  2. add bmp from word doc to mail body
    By DMT Dave in forum Access
    Replies: 1
    Last Post: 05-22-2018, 05:53 PM
  3. convert a surface body into solid body
    By nikhil220404 in forum Access
    Replies: 1
    Last Post: 10-19-2015, 11:02 AM
  4. Adding report content into e-mail Body
    By Toasty in forum Access
    Replies: 22
    Last Post: 08-01-2014, 11:56 AM
  5. Replies: 5
    Last Post: 10-29-2012, 05:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums