N
NancyM
I have an Access 2007 database. I would like to press a buttone and have an
email automatically sent containing several reports from the current database
as attachments. The code I am using is:
Private Sub Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Marmat")
' Set the Subject, Body, and Importance of the message.
.Subject = "D4 Multi Panel PO: " & [Forms]![PurchaseOrder]![txtPO]
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
Set objOutlookAttach = .Attachments.Add([Reports]![PO], olByValue, 1,
"PO")
Set objOutlookAttach = .Attachments.Add([Tables]![PurchaseOrder],
olByValue, 1, "PurchaseOrder")
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
I receive a run-time error 2451
The report "PO" you entered is misspelled or refers to a report that isn't
open or doesn't exist.
The email message is automatically sent if there are no attachments
included, it's only the attachment section that does not work.
Does anyone know how to attach several reports and/or tables from the
current database to one email message?
Any help would be appreciated.
email automatically sent containing several reports from the current database
as attachments. The code I am using is:
Private Sub Email_Click()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Marmat")
' Set the Subject, Body, and Importance of the message.
.Subject = "D4 Multi Panel PO: " & [Forms]![PurchaseOrder]![txtPO]
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
Set objOutlookAttach = .Attachments.Add([Reports]![PO], olByValue, 1,
"PO")
Set objOutlookAttach = .Attachments.Add([Tables]![PurchaseOrder],
olByValue, 1, "PurchaseOrder")
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
I receive a run-time error 2451
The report "PO" you entered is misspelled or refers to a report that isn't
open or doesn't exist.
The email message is automatically sent if there are no attachments
included, it's only the attachment section that does not work.
Does anyone know how to attach several reports and/or tables from the
current database to one email message?
Any help would be appreciated.