SP2 problem with SendObject method - Help!

S

Sandy

Not sure why but the code I've used for a long time is no longer working to
send an object through Outlook. It is prompting the end-user to enter their
exchange login and password. I've tried some new code using shell script to
create an instance of Outlook and it does NOT cause the error, however I'm
not sure how to send a report object to the Body or as an Attachment. I have
had no luck saving the attachment to the user's computer or to a network
folder so I've all but given that up. Your help is much appreciated - below
is my old, and new code that I'm trying to use.

OLD CODE:
DoCmd.SendObject acSendReport, "rptChangeStatistics", _
"SNAPSHOT FORMAT", , , , "PEP STATISTICS CHANGE
NOTIFICATION", _
"Please review attached report" & Chr(13) & "Edit Reason:" & Chr(13)
& [EditReason], no

NEW CODE:
Public Sub SendMessage(Optional AttachmentPath)
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("Sandra Skaar")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Christopher Hagensick")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
..Subject = "This is an Automation test with Microsoft Outlook"
' how to get the report object into the body?
..Body = "Last test - I promise." & vbCrLf & vbCrLf

..Importance = olImportanceHigh 'High importance

'I can't get this to save so I'd rather pass this option up and remove it
from the function

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
..Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top