hi all
what i'm try to do is attach any files from the attachment field from the current open record to email i have some code i have manage to get files from the open record to save to destination /temp folder to work so outlook can attach the files but outlook is not opening or putting them in to email also have problem's that i have highlighed in the code in red
what i'm try to do is attach any files from the attachment field from the current open record to email i have some code i have manage to get files from the open record to save to destination /temp folder to work so outlook can attach the files but outlook is not opening or putting them in to email also have problem's that i have highlighed in the code in red
Code:
Private Sub cmdEmail2_Click()
Dim outlookApp As Outlook.Application
Dim outlookNamespace As NameSpace
Dim objMailItem As MailItem
Dim objFolder As MAPIFolder
Dim strAttachementPath As String
Dim rst As DAO.Recordset2
Dim rstAttachment As DAO.Recordset2
Dim db As DAO.Database
Dim strHTML
'Call SaveAttachment
Set outlookApp = CreateObject("Outlook.Application")
Set outlookNamespace = outlookApp.GetNamespace("mapi")
Set objFolder = outlookNamespace.GetDefaultFolder(olFolderInbox)
Set objMailItem = objFolder.Items.Add(olMailItem)
Set db = CurrentDb
Set rst = db.OpenRecordset("Assets", dbOpenDynaset)
rst.FindFirst "ID = " & Me!ID
Set rstAttachment = rst.Fields("Attachments").Value
strAttachementPath = CurrentProject.Path & "C:\Users\Shane\Documents\Reports for daz\" _
& rstAttachment.Fields("Filename")
' Build HTML for message body.
'strHTML = "<HTML><HEAD>"
'strHTML = "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>ID: </b></br>" & [ID] & "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Date: </b></br>" & [Date] & "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Time: </b></br>" & [Time] & "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Technician: </b></br>" & [Technician] & "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Area: </b></br>" & [Area] & "<br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Blast No.: </b></br>" & [shot number] & "<br><br>"
'strHTML = strHTML & "<FONT Face=Calibri><b>Comments: </b></br>" & [Comments] & "<br>"
'strHTML = strHTML & "</FONT></br><BODY>"
'strHTML = strHTML & "<FONT Face=Arial Color=#ff0000 Size=5>Job #: 123456</FONT></br>"
'strHTML = strHTML & "<FONT Size=3>For: <FONT Size=2></B>a name here</br>"
'strHTML = strHTML & "<FONT Size=3><B>Description: </B><FONT Size=2>description of work to be done</FONT></br>"
strHTML = strHTML & "</BODY></HTML>"
' Build the Email to be sent
With objMailItem
.BodyFormat = olFormatHTML
.To = "EMAIL ADDRESS HERE"
.Subject = "" '"Site Inspection for " & [Area] & " At " & [Date]
' .Body = "Some text here"
.HTMLBody = strHTML
' Grab Attachments for Email if there are any
If rstAttachment.RecordCount > 0 Then
Call SaveAttachment
strAttachementPath = CurrentProject.Path & "C:\Users\Shane\Documents\Reports for daz\" _
& rstAttachment.Fields("Filename")
.Attachments.Add (strAttachementPath) [COLOR=#ff0000]' im get a error here file path incorrect directory[/COLOR]
End If
.Display
End With
outlookApp.ActiveWindow
'SendKeys ("%s")
MsgBox "Mail Sent!", vbOKOnly, "Mail Sent"
'Kill "C:\Users\Shane\Documents\Reports for daz\*.*" ' delete all files in the folder
End Sub
Last edited: