Problem with attachment when sending attachment

hardrock

Registered User.
Local time
Today, 19:37
Joined
Apr 5, 2007
Messages
166
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
 
Last edited:
think you need this:
Code:
    Dim objOutlookAttach As Outlook.Attachment
 
    ...
 
    'Add the attachment to the e-mail message.
    If Not IsMissing(Attachment) Then
        Set objOutlookAttach = .Attachments.Add(Attachment)
    End If
 
    etc.
 
    Set objOutlookAttach = Nothing
 
I think that the word Attachment is a reserved word and as such you need to revise your variable name.

David
 

Users who are viewing this thread

Back
Top Bottom