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
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