Problem with attachment when sending through Outlook
Hi All, I'm using this bit of code to test the feature of sending an automated email to Outlook via MS Access on the click of a button. The bit of code seems to work, however it is putting the attachment right bang center of the email body, instead of inserting the attachment in the attachememt box.
Can any one tell me how to fix this problem? Thanks
*********
Private Sub Command1_Click()
Dim Subject As String
Dim Attachment As String
Dim Recipient As String
Dim BodyText As String
Dim SaveIt As Boolean
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Subject = "Test Email message"
Recipient = "hello@me.com"
Attachment = "D:\xmas.txt"
Mail_Attachment = Attachment
BodyText = "TEST MESSAGE"
SaveIt = True
With MailOutLook
.BodyFormat = olFormatRichText
.To = Recipient
.Subject = Subject
.Body = BodyText
'.Attachments.Add "Attachment"
If Left(Me.Mail_Attachment, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment)
End If
.DeleteAfterSubmit = False
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub
Hi All, I'm using this bit of code to test the feature of sending an automated email to Outlook via MS Access on the click of a button. The bit of code seems to work, however it is putting the attachment right bang center of the email body, instead of inserting the attachment in the attachememt box.
Can any one tell me how to fix this problem? Thanks
*********
Private Sub Command1_Click()
Dim Subject As String
Dim Attachment As String
Dim Recipient As String
Dim BodyText As String
Dim SaveIt As Boolean
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
Subject = "Test Email message"
Recipient = "hello@me.com"
Attachment = "D:\xmas.txt"
Mail_Attachment = Attachment
BodyText = "TEST MESSAGE"
SaveIt = True
With MailOutLook
.BodyFormat = olFormatRichText
.To = Recipient
.Subject = Subject
.Body = BodyText
'.Attachments.Add "Attachment"
If Left(Me.Mail_Attachment, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment)
End If
.DeleteAfterSubmit = False
.Send
End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:
End Sub
Last edited: