Message body

P

Pietro

Hi,

I'm using the below code to send an e-mail with attachment through MS
Access,the code is working perfectly.The only problem is that i want to write
more words in the message body in more than one line,but the code writes the
whole text in one line only even after trying to use Chr$(10) to go to a new
line.
Can anybody help?

The code is:

Private Sub Form_Timer()
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim A As String
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.BodyFormat = olFormatHTML
.To = [Forms]![mail]![To]
.CC = [Forms]![mail]![CC]
.Subject = [Forms]![mail]![Subject]
.HTMLBody = "Attached is Tier2 Daily Report"
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.add (Me.Mail_Attachment_Path)

End If
[Forms]![reporter]![data] = Date - 1
[Forms]![reporter]![Agent] = [Forms]![login]![Agent]

DoCmd.Close acForm, "reporter"
DoCmd.Close acForm, "nr"

Application.Echo False
DoCmd.SelectObject acTable, "", True
DoCmd.RunCommand acCmdWindowHide
Application.Echo True

'.DeleteAfterSubmit = True 'This would let Outlook send th
note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
DoCmd.Close acForm, "mail"


email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message
is: " & Err.Description
Resume Error_out
Error_out:
End Sub
 
S

Stefan Hoffmann

hi Pietro,
I'm using the below code to send an e-mail with attachment through MS
Access,the code is working perfectly.The only problem is that i want to write
more words in the message body in more than one line,but the code writes the
whole text in one line only even after trying to use Chr$(10) to go to a new
line.
You have to use vbCrLf imho. But be aware of the fact, that line breaks
are created automatically. Use it only to begin a new paragraph.


mfG
--> stefan <--
 
P

Pietro

Thank you "Stefan" for your reply...

Can you please mention more details...
I used the below expression between two sentences surrounded by " ",i
expected to have two paragraphs,but actually i get an error "Expected end of
statement"

Please advise with details.
 
A

Aaron_Lin

Pietro said:
Hi,

I'm using the below code to send an e-mail with attachment through MS
Access,the code is working perfectly.The only problem is that i want to
write
more words in the message body in more than one line,but the code writes
the
whole text in one line only even after trying to use Chr$(10) to go to a
new
line.
Can anybody help?

The code is:

Private Sub Form_Timer()
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim A As String
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

With MailOutLook
.BodyFormat = olFormatHTML
.To = [Forms]![mail]![To]
.CC = [Forms]![mail]![CC]
.Subject = [Forms]![mail]![Subject]
.HTMLBody = "Attached is Tier2 Daily Report"
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.add (Me.Mail_Attachment_Path)

End If
[Forms]![reporter]![data] = Date - 1
[Forms]![reporter]![Agent] = [Forms]![login]![Agent]

DoCmd.Close acForm, "reporter"
DoCmd.Close acForm, "nr"

Application.Echo False
DoCmd.SelectObject acTable, "", True
DoCmd.RunCommand acCmdWindowHide
Application.Echo True

'.DeleteAfterSubmit = True 'This would let Outlook send th
note without storing it in your sent bin
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
DoCmd.Close acForm, "mail"


email_error:
MsgBox "An error was encountered." & vbCrLf & "The error
message
is: " & Err.Description
Resume Error_out
Error_out:
End Sub




sorry
 
S

Stefan Hoffmann

hi Pietro,
I used the below expression between two sentences surrounded by " ",i
expected to have two paragraphs,but actually i get an error "Expected end of
statement"
What expression?

btw, as you're using HTMLBody you have to use HTML:

.HTMLBody = "<P>Attached is Tier2 Daily Report" & _
"<BR>" & _
"other line</P>"

for a forced line break or

.HTMLBody = "<P>Attached is Tier2 Daily Report<P>" & _
"<P>other line</P>"

for seperate paragraphs.


mfG
--> stefan <--
 
W

Wayne-I-M

Have a look at Stephans answer and add something like this


"Hi I am the 1st line of this message"& Chr(13) + Chr(10) & String(70, "_") _
"did you like my line above ?"& Chr(13) + Chr(10) & Chr(13) + Chr(10) _
"Hi I am the 2nd papargraph" & Chr(13) + Chr(10) & Chr(13) + Chr(10) _
"Hi - I am the 3rd paragraph"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top