Code to format email message body text

mkdrep

Registered User.
Local time
Yesterday, 20:45
Joined
Feb 6, 2014
Messages
181
I'm using the following code to grab a customer's email address which I grab from [Me.Text7.Value] and create an email which appears as detailed in the attached "Current-email-msg.jpg". Everything is working fine, except for the text in the body of the email (as shown in RED below). This text will stay the same for each email.

I would like to change the text in the body of the email to what is shown in "Desired-email-msg.jpg" but I don't know how to write the code so I can have the line spacing I desire.
--------------------------------------------------------------------------------------------------
Private Sub AIA_Email_Change()

Me.Text7 = Me.Text7 & Me.AIA_Email.Value & ";"

End Sub

Private Sub No_Attachment_Click()

DoCmd.SendObject acSendNoObject, , , Me.Text7.Value, , , "Job with Special-Lite Products specified out for bid", "Sending this email to notify you of a job out for bid which has Special-Lite products specified. Please see attached for details.", True

End Sub
----------------------------------------------------------------------------------------------------------------------
 

Attachments

  • Current-email-msg.jpg
    Current-email-msg.jpg
    32.4 KB · Views: 215
  • Desired-email-msg.jpg
    Desired-email-msg.jpg
    47.1 KB · Views: 215
You can get a line return by concatenating vbCrLf into your string:

"Some text here" & vbCrLf & "more text on the next line."

Edit: That should result in:

Some text here
more text on the next line.
 
In an email, which is HTML, you would use the <p> tag to start a new paragraph:

"This is the first paragraph.<p>This is the second paragraph."

For other html tags (bold, italics, font, etc.) consult this link:

 
Can SendObject send HTML format? I've always used automation when I want HTML format.
 
Thanks guys I eventual used automation and sent the emails out without Outlook. I used the following code
Code:
Public Function CreateEmailWithOutlook( _
    MessageTo As String, _
    Subject As String, _
    MessageBody As String)

    ' Define app variable and get Outlook using the "New" keyword
    Dim olApp As New Outlook.Application
    Dim olEmail As Outlook.MailItem  ' An Outlook Mail item
 
    ' Create a new email object
    Set olEmail = olApp.CreateItem(olMailItem)

    ' Add the To/Subject/Body to the message and display the message
    With olEmail
        .To = MessageTo
        .Subject = Subject
        .HTMLBody = MessageBody
        .Display    ' To show the email message to the user
    End With

End Function

This now does exactly as I want.

Thank you fro yo (y) ur input everyone
 

Users who are viewing this thread

Back
Top Bottom