Re: VBA - Sending Multiple Attachments to Outlook message



Any ideas on this.....
The next Error message is: "Operation is not supported for this type of
object" and Highlights the following line:

newMail.Attachments.Add rs.Fields("FullPathToFile"), olByValue, 1, "Test Doc"

of the following Code:

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 EmailCode = CurrentDb
Set rs = EmailCode.OpenRecordset("Encroachment_Attachments")

newMail.To = "lindabGray@xxxxxxxxxxx"
newMail.Subject = "Encroachment Documents"

While Not rs.EOF
newMail.Attachments.Add rs.Fields("FullPathToFile"), olByValue, 1, "Test
Doc"
Wend

newMail.Display
Set newMailAttachments = Nothing
Set newMail = Nothing
Set objOutlook = Nothing
End Sub





--
Linda


"pietlinden@xxxxxxxxxxx" wrote:

On Jul 15, 3:43 pm, lgray <lindabg...@xxxxxxxxxxx> wrote:
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)

'this is redundant... just use newMail.Attachments.Add(strFile)
Set newMailAttachments = newMail.Attachments
Set EmailCode = CurrentDb
Set rs = EmailCode.OpenRecordset("Encroachment_Attachments")

THE NEXT LINE IS WRONG.
' File1 = rs("FullPathToFile")
newMail.To = "lindabg...@xxxxxxxxxxx"
newMail.Subject = "Encroachment Documents"

While Not rs.EOF
'--THIS DOES NOT MAKE SENSE EITHER
' newMailAttachments.Add File1, olByValue, 1, "Test Doc"
'--DO THIS INSTEAD
newMail.Attachments.Add rs.Fields("FullPathToFile),
olByValue, 1, "Test Doc"
Wend

' newMail.Display '---should be last line in your code.
newMail.Subject = "Documents Confirmation"
newMail.OriginatorDeliveryReportRequested = True
newMail.ReadReceiptRequested = True

'either put .Display here or .SEND
newMail.Send

Set newMailAttachments = Nothing
Set newMail = Nothing
Set objOutlook = Nothing

End Sub

--
Linda


.



Relevant Pages

  • RE: Send Multiple Attachments from Outlook
    ... am trying to get the Recordset bugs worked out. ... Set objOutlook = CreateObject ... Set newMail = objOutlook.CreateItem ... then somehow, through vba, attach them into to an email. ...
    (microsoft.public.access.modulesdaovba)
  • RE: Send Multiple Attachments from Outlook
    ... Dim rs As DAO.Recordset ... Set objOutlook = CreateObject ... Set newMail = objOutlook.CreateItem ... then somehow, through vba, attach them into to an email. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Outlook Attachments via Recordset
    ... Dim EmailCode As Database ... Set objOutlook = CreateObject ... Set newMail = objOutlook.CreateItem ... newMailAttachments.Add File1, olByValue, 1, "Test Doc" ...
    (microsoft.public.access.modulesdaovba)
  • Outlook Attachments via Recordset
    ... newMailAttachments.Add File1, olByValue, 1, "Test Doc" ... Dim EDB_V052708_WIP As Database ... Set objOutlook = CreateObject ... Set newMail = objOutlook.CreateItem ...
    (microsoft.public.access.modulesdaovba)
  • Re: Generate Email from Access with info from table
    ... If I were building a trouble ticket DB ... > Dim objOutlook As Outlook.Application ... > Set newMail = objOutlook.CreateItem ... >> submitting user when they complete the ...
    (microsoft.public.access.modulesdaovba)