L
lgray
Can someone take a look through this code to see if they can find the error
in the code. The code is supposed to cycle through a recordset of
path/files located in a table and attach them into an email.
The email part works, the attachment part works if I hard code the path into
VBA. But when I try to attach the file via a recordset I get an error that
reads. "Cant create file:" It then provides the correct name of the file,
and then reads, "Right-click on the folder you want to create the file in,
and then click Properties on the shortcut menu to check your permissions for
the folder.
On debug, the following message of the code is highlighted:
newMailAttachments.Add File1, olByValue, 1, "Test Doc"
Sub createOutlookMailItem()
Dim EDB_V052708_WIP As Database
Dim rs As Recordset
Dim objOutlook As Outlook.Application
Dim newMail As MailItem
Set objOutlook = CreateObject("Outlook.application")
Set newMail = objOutlook.CreateItem(olMailItem)
Set EDB_V052708_WIP = CurrentDb
Set newMailAttachments = newMail.Attachments
Set rs = EDB_V052708_WIP.OpenRecordset("Select * from
Encroachment_Attachments")
File1 = rs("FullPathToFile")
newMail.To = "(e-mail address removed)"
newMail.Subject = "Encroachment Documents"
While Not rs.EOF
newMailAttachments.Add File1, olByValue, 1, "Test Doc"
Wend
newMail.Display
newMail.Subject = "Documents Confirmation"
newMail.OriginatorDeliveryReportRequested = True
newMail.ReadReceiptRequested = True
newMail.Display
Set newMailAttachments = Nothing
Set newMail = Nothing
Set objOutlook = Nothing
End Sub
in the code. The code is supposed to cycle through a recordset of
path/files located in a table and attach them into an email.
The email part works, the attachment part works if I hard code the path into
VBA. But when I try to attach the file via a recordset I get an error that
reads. "Cant create file:" It then provides the correct name of the file,
and then reads, "Right-click on the folder you want to create the file in,
and then click Properties on the shortcut menu to check your permissions for
the folder.
On debug, the following message of the code is highlighted:
newMailAttachments.Add File1, olByValue, 1, "Test Doc"
Sub createOutlookMailItem()
Dim EDB_V052708_WIP As Database
Dim rs As Recordset
Dim objOutlook As Outlook.Application
Dim newMail As MailItem
Set objOutlook = CreateObject("Outlook.application")
Set newMail = objOutlook.CreateItem(olMailItem)
Set EDB_V052708_WIP = CurrentDb
Set newMailAttachments = newMail.Attachments
Set rs = EDB_V052708_WIP.OpenRecordset("Select * from
Encroachment_Attachments")
File1 = rs("FullPathToFile")
newMail.To = "(e-mail address removed)"
newMail.Subject = "Encroachment Documents"
While Not rs.EOF
newMailAttachments.Add File1, olByValue, 1, "Test Doc"
Wend
newMail.Display
newMail.Subject = "Documents Confirmation"
newMail.OriginatorDeliveryReportRequested = True
newMail.ReadReceiptRequested = True
newMail.Display
Set newMailAttachments = Nothing
Set newMail = Nothing
Set objOutlook = Nothing
End Sub