CJBIRKIN
Drink!
- Local time
- Today, 07:05
- Joined
- May 10, 2002
- Messages
- 256
Hello
Can anyone help please!. I'm populating an excel spreadsheet with 2 queries, saving it, and then calling this function to e-mail the spreadsheet as an attachment. Strangley when the line ".Attachments = XLSReportPath" has executed Access skips out of the function and back to the main sub. Consequently the e-mail is not sent. Any ideas ?
Thanks Chris
Private Function EMailReport(XLSReportPath As String, Addressee As String, Address As String)
Dim olkapps As Outlook.Application
Dim olknamespaces As Outlook.NameSpace
Dim objmailitems As Outlook.MailItem
Set olkapps = New Outlook.Application
Set olknamespaces = GetNamespace("MAPI")
Set objmailitems = olkapps.CreateItem(olMailItem)
With objmailitems
.To = Addressee
.Subject = "KH07 & Census for " & Format(DateAdd("m", -1, Now()), "MMMM YYYY")
.Body = "Hello" & vbCrLf & "Please find enclosed the KH07 & Census for " & Format(DateAdd("m", -1, Now()), "MMMM YYYY")
.Importance = olImportanceHigh
.Attachments = XLSReportPath
.Send
End With
Set objmailitems = Nothing
Set olknamespaces = Nothing
Set olkapps = Nothing
End Function
Can anyone help please!. I'm populating an excel spreadsheet with 2 queries, saving it, and then calling this function to e-mail the spreadsheet as an attachment. Strangley when the line ".Attachments = XLSReportPath" has executed Access skips out of the function and back to the main sub. Consequently the e-mail is not sent. Any ideas ?
Thanks Chris
Private Function EMailReport(XLSReportPath As String, Addressee As String, Address As String)
Dim olkapps As Outlook.Application
Dim olknamespaces As Outlook.NameSpace
Dim objmailitems As Outlook.MailItem
Set olkapps = New Outlook.Application
Set olknamespaces = GetNamespace("MAPI")
Set objmailitems = olkapps.CreateItem(olMailItem)
With objmailitems
.To = Addressee
.Subject = "KH07 & Census for " & Format(DateAdd("m", -1, Now()), "MMMM YYYY")
.Body = "Hello" & vbCrLf & "Please find enclosed the KH07 & Census for " & Format(DateAdd("m", -1, Now()), "MMMM YYYY")
.Importance = olImportanceHigh
.Attachments = XLSReportPath
.Send
End With
Set objmailitems = Nothing
Set olknamespaces = Nothing
Set olkapps = Nothing
End Function