Hello,I found the code below on Microsoft Answers which supposedly copies all files in the 'Attachments' field to a temporary location on your hard drive, which you can point to using my 'send email' code below. Im not quite sure how it all fits together....like the order and what all needs to go where. But I would like to be able to incorporate all the code together and have it send an email with attachments with the click of one command button.
Suggested code:
i just wrote this little function for you this will save your Attachment on your harddrive.
Dim db As DAO.Database
Dim rst As DAO.Recordset2
Dim rstAttachment As DAO.Recordset2
Dim fld As DAO.Field2
Dim strPath As String
Dim intz As Integer
Set db = CurrentDb
Set rst = db.OpenRecordset("tabelle1", dbOpenDynaset)
rst.FindFirst "ID = " & Me!ID
Set rstAttachment = rst.Fields("Feld1").Value
Set fld = rstAttachment.Fields("Filedata")
strPath = CurrentProject.Path & "\" _
& rstAttachment.Fields("Filename")
On Error Resume Next
Kill strPath
On Error GoTo 0
fld.SaveToFile strPath
rstAttachment.Close
rst.Close
Set rstAttachment = Nothing
Set rst = Nothing
Set db = Nothing
You can add the mailcode to it and use strPath in the AttachmentAdd-Statement. And at the end you can use kill to delete the attachment. when the mail was send.
_______________________________
My 'Send Email' Code:
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)
With MailOutLook
.BodyFormat = olFormatRichText
.To = "
email address"
.CC = "email addresss"
.Subject = "test"
.HTMLBody = "test"
.Attachments.Add " "
'Send email
'.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
.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