Hello,
I am wishing to add a number of attachments to an email.
I have the code below which sends the email OK, but does not attach the files. The path for the file is storeed in textboxs on the form. Many thanks Mark
I am wishing to add a number of attachments to an email.
I have the code below which sends the email OK, but does not attach the files. The path for the file is storeed in textboxs on the form. Many thanks Mark
Code:
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = Me.txt_Email_To
.Subject = Me.txt_Email_Subject
.Body = Me.txt_Email_Body
.Attachments.Add = Me.txt_Email_Attachment_1
.Attachments.Add = Me.txt_Email_Attachment_2
.Attachments.Add = Me.txt_Email_Attachment_3
.Send
End With
Me.chk_email_sent = True
'If bStarted Then
' 'If we started Outlook from code, then close it
' oOutlookApp.Quit
'End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing