Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic E-Mail Format 1

Status
Not open for further replies.

mab43

Technical User
Aug 5, 2004
11
I am using the code below to generate automatic e-mails from a form in Access. I had so many issues with the Outlook automation due to system differences, so I decided to use the approach mentioned in FAQ705-537. It works fine, except when it populates the e-mail, it will not put in a return (new line) in the txtbody where indicated. Anyone know how to get the generated e-mail to format properly?

Module Code
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Command Buttom Code
On Error GoTo Err_cmdEMail_Click

Dim stext As String
Dim saddedtext As String
Dim txtsubject As String
Dim txtbody As String

With frm_Action_Item

txtsubject = "Action Item Status for Item No. TSF-05-" & Me.Item_ID

txtbody = "Action Item Status for Item No. TSF-05-" & Me.Item_ID & vbCrLf & _
"Description: " & Me.Item_Description & vbCrLf & _
"Derived From: " & Me.Derived_From & vbCrLf & _
"Due Date: " & Me.Date_Due & vbCrLf & _
"Response Type: " & Me.Response_Type & vbCrLf & _
"Comments: " & Me.Comments & vbCrLf

End With

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
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_cmdEMail_Click:
Exit Sub

Err_cmdEMail_Click:
MsgBox Err.Description
Resume Exit_cmdEMail_Click

End Sub

 
Are you sure you want new line in subject ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I would like the new line in the body (txtbody) of the e-mail after each item. It does not seem to recognize the vbCrLf and runs it all together. Thanks for your help.
 
If the mail body format is HTML then replace vbCrLf by "<BR>"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the recommendation. When I used "<BR>", it puts it in the text. Not sure what else to do. In the meantime, I included semi-colons in the text body, so it provides some separation of the items.
 
So, if plain text, you may try to replace vbCrLf by vbNewLine

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks again, but I am still getting the same result. I think I will just go with the semi-colons. Appreciate your effort. MAB2005
 
hi dont know if you found this or not...

& "%0D%0A" (for return)
& "%0D%0A" & "%0D%0A" & _ (for new line and space)
 
It worked - Thank you, Thank you, Thank you!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top