L
lgray
Is there anybody out there that can go through this simple code and see what
I've done wrong? I'm still novice, trying to do something new... I'm trying
to go through a recordset to attach files; where a table holds the path to
the attachment. The outlook attachment part of the code works when I hard
code the path into the script, but when I implement the recordset I get an
error that reads...
"Run-time error '-2147467259 (80004005)'
Can't create file: Test1.doc. Right-click the folder you want to create the
file in, and then click Properties on the shortcut menu to check your
permissions for the folder."
Where "Test1.doc" is the name of the file in the table. The table has a
field that holds the file path and the name of the document (again,
Test1.doc, in this example)
The code is below:
Sub createOutlookMailItem()
Dim EmailCode 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 newMailAttachments = newMail.Attachments
Set EmailCode = CurrentDb
Set rs = EmailCode.OpenRecordset("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
I've done wrong? I'm still novice, trying to do something new... I'm trying
to go through a recordset to attach files; where a table holds the path to
the attachment. The outlook attachment part of the code works when I hard
code the path into the script, but when I implement the recordset I get an
error that reads...
"Run-time error '-2147467259 (80004005)'
Can't create file: Test1.doc. Right-click the folder you want to create the
file in, and then click Properties on the shortcut menu to check your
permissions for the folder."
Where "Test1.doc" is the name of the file in the table. The table has a
field that holds the file path and the name of the document (again,
Test1.doc, in this example)
The code is below:
Sub createOutlookMailItem()
Dim EmailCode 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 newMailAttachments = newMail.Attachments
Set EmailCode = CurrentDb
Set rs = EmailCode.OpenRecordset("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