Insert new paragraph in email from vba code

  • Thread starter icsupt via AccessMonster.com
  • Start date
I

icsupt via AccessMonster.com

I have the below code. What I am trying to do is to have an email generated
from a form. The form has several fields that I would like included in the
email:

Addressees
Subject
txtbody1
txtproducts1
txtproducts2
txtproducts3
txtproducts4
txtproducts5
txtbody2

I would like the email to have txtbody1 as the first paragraph. Then a blank
line and then have txtproducts1 through txtproducts5 as bullets underneath
txtbody1. Then another blank line and then txtbody2.

Right now, everything is in one paragraph. I am not sure how to insert blank
lines in code so they can be separate paragraphs. Can anyone tell me what I
am doing wrong here? Thanks in advance.

Private Sub Command29_Click()
On Error GoTo Err_Command0_Click

Dim stext As String
Dim sAddedtext As String



If Len(txtMainAddresses) Then
stext = txtMainAddresses
End If
If Len(txtCC) Then
sAddedtext = sAddedtext & "&CC=" & txtCC
End If
If Len(txtBCC) Then
sAddedtext = sAddedtext & "&BCC=" & txtBCC
End If
If Len(txtSubject) Then
sAddedtext = sAddedtext & "&Subject=" & txtSubject
End If
If Len(txtBody) Then
sAddedtext = sAddedtext & "&Body=" & txtBody & " " & txtProducts1 & "
" & txtbody2
End If

'If Len(txtAttachment) Then
' sAddedtext = sAddedtext & "Attach=" & Chr$(34) & txtAttachment & Chr
$(34)
'End If

stext = "mailto:" & stext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If

stext = stext & sAddedtext

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
SW_SHOWNORMAL)
End If
Exit_Command0_Click:
Exit Sub


Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
'End If
End Sub
 
G

Gerald Stanley

You should be able to achieve the desired effect by including the literal
vbCrLf in your string. Use it once to start a new line and twice to start a
new paragraph.

Hope This Helps
Gerald Stanley MCSD
 
I

icsupt via AccessMonster.com

I tried putting the vbCrLf in and it does not work (see the code below for
what I did). What am I doing wrong? Help! Thanks so much.

Private Sub Command29_Click()
On Error GoTo Err_Command0_Click

Dim stext As String
Dim sAddedtext As String



If Len(txtMainAddresses) Then
stext = txtMainAddresses
End If
If Len(txtCC) Then
sAddedtext = sAddedtext & "&CC=" & txtCC
End If
If Len(txtBCC) Then
sAddedtext = sAddedtext & "&BCC=" & txtBCC
End If
If Len(txtSubject) Then
sAddedtext = sAddedtext & "&Subject=" & txtSubject
End If

If Len(txtBody) Then
' sAddedtext = sAddedtext & "&Body=" & "this is a test" & Chr(10) & Chr
(13) & "this is another test"
' sAddedtext = sAddedtext & "&Body=" & txtBody & Chr(10) & Chr(13) &
txtProducts1 & txtbody2
sAddedtext = sAddedtext & "&Body=" & txtBody & vbCrLf & vbCrLf &
txtProducts1 & txtbody2


End If

'If Len(txtAttachment) Then
' sAddedtext = sAddedtext & "Attach=" & Chr$(34) & txtAttachment & Chr
$(34)
'End If

stext = "mailto:" & stext

If Len(sAddedtext) <> 0 Then
Mid$(sAddedtext, 1, 1) = "?"
End If

stext = stext & sAddedtext

' launch default e-mail program
If Len(stext) Then
Call ShellExecute(hwnd, "open", stext, vbNullString, vbNullString,
SW_SHOWNORMAL)
End If
Exit_Command0_Click:
Exit Sub


Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
'End If
End Sub
 
R

Rick Brandt

icsupt via AccessMonster.com said:
I tried putting the vbCrLf in and it does not work (see the code below for
what I did). What am I doing wrong? Help! Thanks so much. [snip]
If Len(txtBody) Then
' sAddedtext = sAddedtext & "&Body=" & "this is a test" & Chr(10) & Chr
(13) & "this is another test"
[snip]

Chr(13) comes before Chr(10)
 

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

Top