carriage return in control

teel73

Registered User.
Local time
Yesterday, 20:30
Joined
Jun 26, 2007
Messages
205
I have a button that sends an email using data from the text boxes on the form. The email uses HTML tags. Everything works just fine except I can't get the HTML to read if the text box has carriage returns. For example, the following 2 sentences are entered into the textbox which includes a line break after the 1st sentence:

"Areas of dense fog this morning.

Cloudy with a slight chance of rain this morning...then partly sunny this "

However, the email comes out with those two sentences on 1 line. So, is there a way for outlook to recognize when to use a break? Here's my code:

Code:
Public myItem As Outlook.MailItem
Public nxtUpdate As Variant
Function SendReport()
Dim theTo, theSub, thecc As String
Dim frm As Form
Dim wCondition, wForecast, wFacilityCondition, wAreaClosings As String

Set frm = Form_frmWeatherReports
theSub = "Weather Report"
theTo = "[EMAIL="tarsha_lewis@fmminc.com"]tarsha_lewis@fmminc.com[/EMAIL]"
wCondition = frm!cboCondition & ", " & frm!cboTemp & " degrees"
wForecast = frm!Forecast
wFacilityCondition = frm!FacilityConditions
nxtUpdate = DateAdd("h", 4, Time)
Set olApplication = CreateObject("Outlook.Application")
Set olns = olApplication.GetNamespace("MAPI")
Set myItem = olApplication.CreateItem(olMailItem)
myItem.HTMLBody = "<HTML><BODY><P><b>Date:</b>  " & Date & "<br>" & _
"<b>Time:</b>  " & Format(Time, "h:nn AM/PM") & "</p>" & _
"<br>" & _
"<P><b>Current Weather Conditions</b><br>" & wCondition & "</p>" & _
"<br>" & _
"<P><b>Forecast</b><br>" & wForecast & "</p>" & _
"<br>" & _
"<P><b>Facilities Conditions</b><br>" & wFacilityCondition & "</p>" & _
"<br>" & _
"<P><b>Area Closings</b><br><br>" & _
"<b>Federal Government:</b>  " & frm!cboOPM & "<br>" & _
"<b>State and Local Government:</b>  " & frm!cboGovt & "<br>" & _
"<b>State and Local Schools:</b>  " & frm!cboSchool & "</p>" & _
"<br> " & _
"<P><b>Recommended Operational Status</b><br>" & frm!cboCodes & "</p>" & _
"<br>" & _
"<P><b>Next Update</b><br>" & nxtUpdate & "</p>" _

myItem.Subject = theSub
myItem.To = "" & theTo
myItem.Display
 
You should be able to use vbCrLf to insert a carriage return and line feed into your text.
 
The <br> should work fine with the HTML but the question is, have you set the option to use HTML mail first? You are setting the HTML body but you don't appear to have told it to send using HTML mail.
 
Yes. I tell it to use HTML. This is the code that I have in the Option Compare part of the module:

Code:
Public olApplication As Outlook.Application
Public olns As Outlook.Namespace
Public myItem As Outlook.MailItem


The email function work properly. The <br> tags work fine. That isn't my problem.. The issue is the text that is captured from the text box is what I can't get HTML to recognize that there's a line break inside the textbox or control...

Think of it like this.. on my form I have a textbox control named [txtCondition] where I type in the following sentence:

"Areas of dense fog this morning.

Cloudy with a slight chance of rain this morning...then partly sunny this "


In my code, I set the variable "wCondition" to equal the value of [txtCondition].

So if I just initiate the code below:

[CODE\Set olApplication = CreateObject("Outlook.Application")
Set olns = olApplication.GetNamespace("MAPI")
Set myItem = olApplication.CreateItem(olMailItem)

myItem.HTMLBody = "<HTML><BODY><P>" & wCondition & "</P>"

myItem.To = info@ttt.tech.com
myItem.Send

[/CODE]


My email displays the correct value of "wCondition" but just without the line break: It displays like this:

"Areas of dense fog this morning.
Cloudy with a slight chance of rain this morning...then partly sunny this "
 
myItem.HTMLBody = "<HTML><BODY><P>" & wCondition & "</P>"
Try this:
Code:
myItem.HTMLBody = "<HTML><BODY><P>" & [B][COLOR=red]Replace(wCondition, vbCrLf, "<br>")[/COLOR][/B] & "</P>"
 
Actually, I'm sorry .. that did work!!! .. I was specifying the wrong control .. "I'm a Dummy" .. LOL .. Thanks SOOOOO much!!
 
Last edited:
Since it isn't necessarily a complete carriage return and line feed, it might need to be one of these:
Code:
myItem.HTMLBody = "<HTML><BODY><P>" & Replace(wCondition, Chr(13), "<br>") & "</P>
Code:
myItem.HTMLBody = "<HTML><BODY><P>" & Replace(wCondition, Chr(10), "<br>") & "</P>"
Code:
myItem.HTMLBody = "<HTML><BODY><P>" & Replace(wCondition, vbNewLine, "<br>") & "</P>"
See if any of those does it.
 

Users who are viewing this thread

Back
Top Bottom