hi
right i have played a little bit more get error file or directory can find even tho i no the directory is right ??
cheers shane
code :
Code:
Function SaveAttachment()
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("Attachments").Value
While Not rsChild.EOF
If Dir("C:\Users\Shane\Documents\Reports for daz", vbDirectory) = "" Then
MkDir ("C:\Users\Shane\Documents\Reports for daz")
Else
'do nothing for the "C:\dbtemp" directory already exists
'MsgBox "C:\dbtemp\ directory already exists"
End If
rsChild.OpenRecordset
rsChild.Fields("FileData").SaveToFile ("C:\Users\Shane\Documents\Reports for daz\")
rsChild.MoveNext
Wend
End Function
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) ' im get a error here file path incorrect directory
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