|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Hi,
I need to send a report that is in my Access database as the body of an email. The following code works to send an attachment but for some reason when I dim a var for report object nad trying to set the message body to the report var I am not having any luck. :-(
I cannot use docmd.sendobject because it causes Outlook to prompt for the user to enter their exchange server login and password due to an SP2 upgrade. I must use the shell script below.
Please I have looked for help on this and am not having a lot of luck. Your help is appreciated!
Thank you,
S. Skaar
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.
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 Dim myReport as Report
myReport.Name = "rptTeamList"
' 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("Coaches") objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message. Set objOutlookRecip = .Recipients.Add("Leaders") objOutlookRecip.Type = olCC
' Set the Subject, Body, and Importance of the message. ..Subject = "Team List Report" ' how to get the report object into the body? ..Body = myReport ..Importance = olImportanceHigh 'High importance
'I can't get the report to save to the users C: directory with Outputto, so this really isn't an option
' 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
|
|
The line below would output your report to the directory the database resides in:
DoCmd.OutputTo acOutputReport, "myReport", "RichTextFormat(*.rtf)", CurrentProject.Path & "\MyReport.rtf"
"Sandy" wrote:
[Quoted Text] > Hi, > > I need to send a report that is in my Access database as the body of an > email. The following code works to send an attachment but for some reason > when I dim a var for report object nad trying to set the message body to the > report var I am not having any luck. :-( > > I cannot use docmd.sendobject because it causes Outlook to prompt for the > user to enter their exchange server login and password due to an SP2 upgrade. > I must use the shell script below. > > Please I have looked for help on this and am not having a lot of luck. Your > help is appreciated! > > Thank you, > > S. Skaar > > 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. > > 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 > Dim myReport as Report > > myReport.Name = "rptTeamList" > > ' 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("Coaches") > objOutlookRecip.Type = olTo > > ' Add the CC recipient(s) to the message. > Set objOutlookRecip = .Recipients.Add("Leaders") > objOutlookRecip.Type = olCC > > ' Set the Subject, Body, and Importance of the message. > .Subject = "Team List Report" > ' how to get the report object into the body? > .Body = myReport > .Importance = olImportanceHigh 'High importance > > 'I can't get the report to save to the users C: directory with Outputto, so > this really isn't an option > > ' 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 >
|
|
Thanks Ralph,
Unfortunately I tried this line of code prior to my post and received an error that I can not save to this directory, even though I have administrative access to the folder. I believe there are some security issues that exist with the recent SP2 upgrade that are preventing this as an option.
Do you know of a way to just pass in a variable as the report name and assign it to an object variable, which I can then attach to the email as the message body?
Thanks for your help,
Sandy
"Ralph" wrote:
[Quoted Text] > The line below would output your report to the directory the database resides > in: > > DoCmd.OutputTo acOutputReport, "myReport", "RichTextFormat(*.rtf)", > CurrentProject.Path & "\MyReport.rtf" > > "Sandy" wrote: > > > Hi, > > > > I need to send a report that is in my Access database as the body of an > > email. The following code works to send an attachment but for some reason > > when I dim a var for report object nad trying to set the message body to the > > report var I am not having any luck. :-( > > > > I cannot use docmd.sendobject because it causes Outlook to prompt for the > > user to enter their exchange server login and password due to an SP2 upgrade. > > I must use the shell script below. > > > > Please I have looked for help on this and am not having a lot of luck. Your > > help is appreciated! > > > > Thank you, > > > > S. Skaar > > > > 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. > > > > 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 > > Dim myReport as Report > > > > myReport.Name = "rptTeamList" > > > > ' 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("Coaches") > > objOutlookRecip.Type = olTo > > > > ' Add the CC recipient(s) to the message. > > Set objOutlookRecip = .Recipients.Add("Leaders") > > objOutlookRecip.Type = olCC > > > > ' Set the Subject, Body, and Importance of the message. > > .Subject = "Team List Report" > > ' how to get the report object into the body? > > .Body = myReport > > .Importance = olImportanceHigh 'High importance > > > > 'I can't get the report to save to the users C: directory with Outputto, so > > this really isn't an option > > > > ' 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 > >
|
|
Hi Ralph,
Guess what - I tried it and it worked! Your code was different than mine for the Output format - I wonder if that was the problem? In any case you are a life saver!
Thanks a million!
Sandy
"Ralph" wrote:
[Quoted Text] > The line below would output your report to the directory the database resides > in: > > DoCmd.OutputTo acOutputReport, "myReport", "RichTextFormat(*.rtf)", > CurrentProject.Path & "\MyReport.rtf" > > "Sandy" wrote: > > > Hi, > > > > I need to send a report that is in my Access database as the body of an > > email. The following code works to send an attachment but for some reason > > when I dim a var for report object nad trying to set the message body to the > > report var I am not having any luck. :-( > > > > I cannot use docmd.sendobject because it causes Outlook to prompt for the > > user to enter their exchange server login and password due to an SP2 upgrade. > > I must use the shell script below. > > > > Please I have looked for help on this and am not having a lot of luck. Your > > help is appreciated! > > > > Thank you, > > > > S. Skaar > > > > 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. > > > > 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 > > Dim myReport as Report > > > > myReport.Name = "rptTeamList" > > > > ' 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("Coaches") > > objOutlookRecip.Type = olTo > > > > ' Add the CC recipient(s) to the message. > > Set objOutlookRecip = .Recipients.Add("Leaders") > > objOutlookRecip.Type = olCC > > > > ' Set the Subject, Body, and Importance of the message. > > .Subject = "Team List Report" > > ' how to get the report object into the body? > > .Body = myReport > > .Importance = olImportanceHigh 'High importance > > > > 'I can't get the report to save to the users C: directory with Outputto, so > > this really isn't an option > > > > ' 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 > >
|
|
|