Line breaks in email

I have some code that sends out an email in Access 2003.

"Line1" & vbCrLf & _
"Line2" & vbCrLf & _
vbCrLf & vbCrLf & vbCrLf & _
            "We respect your privacy. " &  vbCrLf

That is then put with some other text.  It works and the output in the email is neatly formatted as:


West respect your privacy.

However when that email is replied to that same text is reformatted as:

Line1 Line2

West respect your privacy.

Is it possible to prevent this and keep my line breaks in a replied email?  (Using Outlook 2003)  I'm thinking that Outlook is removing extra spaces?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I think almost all email clients reformat the content to some degree when you reply or forward.  If you do something as simple as going from plain text to HTML format, things will change because the line break methods are different.  I think what you are wanting is impossible to guarantee.
NorieVBA ExpertCommented:
It could be Outlook, or whatever the mail client is,  on the receiving side that's losing th formatting.

I know that's happened to me in the past, you send a nicely formatted message and it comes back as part of the reply in a bit of a jumble.
thandelAuthor Commented:
Exactly.... the rest is holding just these few lines loosing the return... hoping to find a resolve.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

You show some basic code that apparently generates e-mail. Can you show the actual generated text? The generated text will be where any solution becomes apparent, if at all.

thandelAuthor Commented:
The generated text was pasted into the question.
Dave BaldwinFixer of ProblemsCommented:
If the recipient replies in HTML format, the line breaks in your plain text format are ignored.  Line breaks in HTML require the <br> tag, not vbCrLf or cr/lf or \r\n.  I'm sure Outlook is doing some reformatting also.
To troubleshoot, you could have your code format up the email message as HTML and see what happens

Instead of .Body = "some strings"

you'd have

.BodyFormat = olFormatHTML
.HTMLBody = "Line1" & "<br>"
.HTMLBody =.HTMLBody & "Line2" & "<br>"
.HTMLBody =.HTMLBody & "<br><br><br>We respect your privacy.<br>"

If Outlook is the formatting villain, this may get you around it
(When I do code like this I use an Outlook reference, and can therfore use the constant olFormatHTML.  I am not sure what number it represents, if you are using late-binding)
Jeffrey CoachmanMIS LiasonCommented:
I'm with imnorie...

I have Outlook (set to send/read in HTML) and the reply looks fine.
(Line breaks look the same as in the reply as in the original email)

This may be an issue with the recipients email settings.

In which case there may not be that much you can do, ..short of *forcing* them to change their settings...

...You can go all out and create the email via Automation (then try using .HTMLBody and using  <br> instead of vbcrlf...) but even this may not work, and seems like overkill...

The generated text was pasted into the question.

What you pasted does not look like valid SMTP text. But if those are indeed the actual characters in the SMTP text (which seems unlikely), then what characters are you using for carriage-return (CR) and line-feed (LF)? CR should be 7-bit ASCII code 13, and LF should be 7-bit ASCII code 10.

Note that the physical text of a SMTP e-mail is not HTML nor RTF nor anything other than quoted-printable 7-bit ASCII. So, the actual text portion is needed rather than any HTML or RTF or other embedded attachment such as is created for HTML mail for example.

NorieVBA ExpertCommented:

vbCrLf is Chr(13) & Char(10).

If you try Len(vbCrLf) in VBA it returns 2.
If you try Len(vbCrLf) in VBA it returns 2.

True, but that is not what the actual text of the e-mail will be. The definition of the issue will involve the physical text of an e-mail item, not any program/script statements that create an e-mail.

In order to have an idea about what some (possibly unknown) e-mail client is going to do with an item, it is necessary to know what is actually received by clients. From there, it can be worked backwards to code that generates and to probable changes that will generate more predictable e-mail.

If an e-mail item is saved as a file and then opened with, e.g., Notepad, the actual item will be seen. That's what should illuminate probable causes of strange or undesired behaviors.

My underlying assumption from the code the OP posted is that VBA is being used in Access to automate Outlook.  Another possibility is DoCmd.SendObject.  Either one of these methods only takes strings for inputs to the message body.  If you are automating Outlook, you can specify that you'd like HTML output and feed in an appropriately formatted bit of HTML  as a string.

But I don't think that there is much else that VBA/Access can do with either of these two methods to muck with formatting.  The vagarities of the receiving client cannot likely be overcome.
thandelAuthor Commented:
Well in order to send this emails without minimun Outlook security alerts and to keep code simple I used.

DoCmd.SendObject , , , Me.Email, , , sSubject, sBody

As far as I can tell I can not use any sort of HTML code with SendOjbect.  I think the sort answer to my question is its not possible.
I'd have to agree.
SendObject is pretty rudimentary.

Automating Outlook does have some benefits as well as the one security prompt drawback.
For one, the resulting email winds up in Sent Items which can be nice for traceablity.

But now, from the Access 2003 help

The SendObject method carries out the SendObject action in Visual Basic.

expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
expression    Required. An expression that returns one of the objects in the Applies To list.

ObjectType   Optional AcSendObjectType.

AcSendObjectType can be one of these AcSendObjectType constants.
acSendNoObject default

ObjectName   Optional Variant. A string expression that's the valid name of an object of the type selected by the objecttype    argument. If you want to include the active object in the mail message, specify the object's type with the objecttype    argument and leave this argument blank. If you leave both the objecttype    and objectname    arguments blank (the default constant, acSendNoObject, is assumed for the objecttype    argument), Microsoft Access sends a message to the electronic mail application without an included database object. If you run Visual Basic code containing the SendObject method in a library database, Microsoft Access looks for the object with this name first in the library database, then in the current database.

OutputFormat   Optional Variant.

To   Optional Variant. A string expression that lists the recipients whose names you want to put on the To line in the mail message. Separate the recipient names you specify in this argument and in the cc    and bcc    arguments with a semicolon (;) or with the list separator set on the Number tab of the Regional Settings Properties dialog box in Windows Control Panel. If the recipient names aren't recognized by the mail application, the message isn't sent and an error occurs. If you leave this argument blank, Microsoft Access prompts you for the recipients.

Cc   Optional Variant. A string expression that lists the recipients whose names you want to put on the Cc line in the mail message. If you leave this argument blank, the Cc line in the mail message is blank.

Bcc   Optional Variant. A string expression that lists the recipients whose names you want to put on the Bcc line in the mail message. If you leave this argument blank, the Bcc line in the mail message is blank.

Subject   Optional Variant. A string expression containing the text you want to put on the Subject line in the mail message. If you leave this argument blank, the Subject line in the mail message is blank.

MessageText   Optional Variant. A string expression containing the text you want to include in the body of the mail message, after the object. If you leave this argument blank, the object is all that's included in the body of the mail message.

EditMessage   Optional Variant. Use True (–1) to open the electronic mail application immediately with the message loaded, so the message can be edited. Use False (0) to send the message without editing it. If you leave this argument blank, the default (True) is assumed.

TemplateFile  Optional Variant. A string expression that's the full name, including the path, of the file you want to use as a template for an HTML file.

EditMessage and TemplateFile would seem to imply that you can use HTML, and that you can have the message open before actually sending it.
If you do so, what does it look like?
thandelAuthor Commented:
If I preview before sending the format is fine.  So the odd part is that if I don't send it and then click on reply (from the outbox) then the wrap issue returns... but looking at the email in the outbook the wrap is fine????? So its like Outlook is loosing the format after its sending or when using the same email in a reply.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.