Code to format email message body text (1 Viewer)

mkdrep

Registered User.
Local time
Today, 11:46
Joined
Feb 6, 2014
Messages
176
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: 187
  • Desired-email-msg.jpg
    Desired-email-msg.jpg
    47.1 KB · Views: 189

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:46
Joined
Aug 30, 2003
Messages
36,124
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.
 

plog

Banishment Pending
Local time
Today, 10:46
Joined
May 11, 2011
Messages
11,638
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:

 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:46
Joined
Aug 30, 2003
Messages
36,124
Can SendObject send HTML format? I've always used automation when I want HTML format.
 

atrium

Registered User.
Local time
Tomorrow, 01:46
Joined
May 13, 2014
Messages
348
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

Top Bottom