How to retain field paragraphs when transferring to an email body (1 Viewer)

jjake

Registered User.
Local time
Today, 02:47
Joined
Oct 8, 2015
Messages
291
Hello,

I'm using the following code to generate an email.

Code:
Option Compare Database

Private Sub SendEmail_Click()

Dim olApp As New Outlook.Application
Dim mItem As Outlook.MailItem  ' An Outlook Mail item

Set olApp = CreateObject("Outlook.Application")
Set mItem = olApp.CreateItem(olMailItem)
' Add the To/Subject/Body to the message and display the message

MessageTo = fConcatEMailAddr

Forms!frmMOCform.SetFocus

Subject = "MOC# " & [Forms]![frmMOCform]![MOCNum] & " Update"

MessageBody = "<b>An update has been made to an MOC in the Production MOC database. Please login and provide your response.</b>" & "<br>" _
             & "<br>" _
             & "<br>" _
             & "MOC# " & Me.MOCNum & "<br>" _
             & "Product Name: " & Me.PRODUCTNAME & "<br>" _
             & "Product SAP Code: " & Me.PRODUCTSAPCODE & "<br>" _
             & "<br>" _
             & "<br>" _
             & "<u>Update Notes</U>" & "<br>" _
             & "<br>" _
             & "<br>" _
             & Me.Updates
      
 
With mItem
    .To = MessageTo
    .Subject = Subject
    .HTMLBody = MessageBody
    .Display    ' To show the email message to the user
End With

' Release all object variables
Set mItem = Nothing
Set olApp = Nothing

MsgBox "MOC Update submitted successfully"
 
DoCmd.Close acForm, "frmUsersUpdate", acSaveYes
DoCmd.Close acForm, "frmMOCForm", acSaveYes


End Sub


The code runs fine but the this particular field uses the "New line in field" Enter Key Behavior so keeping the format is important.

My form field shows the following

Code:
abc

123

xyz

But when i run the code it changes to,

Code:
abc123xyz

How would i keep that formatting from the field?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:47
Joined
Oct 29, 2018
Messages
21,358
Hi. What is the name of the field? Try using something like:
Code:
Replace([FieldName],vbCrLf,"<br>")
Hope it helps...
 

jjake

Registered User.
Local time
Today, 02:47
Joined
Oct 8, 2015
Messages
291
That did the trick. Thanks.
 

Users who are viewing this thread

Top Bottom