I am trying to program a button which will create an email and send out two reports as attachments. A catch is that I would like the email to remain open for the user to modify the email text if required.
I have used the DoCmd.SendObject command in the past and it words will for a single report. But now that I have two reports to attach AND I want the user to be able to edit the email before it is sent, I need a suggestion on how to handle this.
Microsoft AccessVB ScriptVisual Basic.NET
Last Comment
Jeffrey Coachman
8/22/2022 - Mon
danishani
Best approach is to use the Outlook Object to automate your process and to have more control on attachments and to Edit your e-mail.
It looks like these examples all require the attachments to be precreated and saved somewhere on the computer. I don't currently have it programmed this way. The two attachements are sort of real time reports within access. Is there an easy way to do this?
The easy way is have the attachments to be precreated and saved somewhere on the computer. If you want real-time reports you would have to use SQL Server Reporting Services tied directly to the SQL Server whereby a link is sent via email and they click on it and get data real-time.
With Access all you can do is print out the reports as the data is in that point in time and then send the report - which in essence all a report is....because people can change the data after the report is run - doesn't mean its going to refresh.
I usually export mine to a pdf to a c:\local temp location and then do as the above Outlook VBA coding that the experts have shown...
To export as PDF with Access 2007 (be sure you have all your Service Packs for Office 2007 SP2)-
Experts:
Sorry, I was not very clear with my last post. I have not yet played with saving reports to the computer. I just need to make sure that there are not issues with overwriting these temporary attachement files when the code is run a second time. Let me play around with this information and get back.
shrimpfork
ASKER
I am using a couple suggestions above (primarily boag2000's suggestion) and have it working except for a couple items. I have a string of 2-3 emails that is in the TO field and 2 more in the CC field of the email. These are all address and not true "recipients". I am separating all the emails with a semi-colon. When the program (outlook) resolves the addresses (or when the send button is clicked), it returns the "Check Names" dialog box for only the TO field. It reads the string of emails as a single email address. If I click in the TO field and back out of it, Outlook separates all the address correctly. Any ideas what is wrong?
To is not a collection; rather, it is a delimited string.
Recipients, OTOH, is a collection.
:)
Patrick
Jeffrey Coachman
< I have a string of 2-3 emails that is in the TO field and 2 more in the CC field of the email.>
These are new requirements, not mentioned in your original post.
If the Recipients and the CC will always be the same people, I would create a distribution list for the Recipients and another for the CCs.
The you could just reference them with syntax something like so:
Set objOutlookRecip = .Recipients.Add("RecipientsDistributionListName")
You would do the same for the CCs as well...
JeffCoachman
shrimpfork
ASKER
The addresses are project specific. I can not use a distribution name for this. I have it configured as a string.
I've played around with it and it seam like only the CC field is resolving correctly. The TO string is fine, because if I change the code to insert the TO string into the CC field the CC field resolves fine, and if I put the CC string into the TO field it will not resolve the TO field. It looks like it is an outlook problem.
Thank you Experts! I got it up and running. Boag2000, your response was the quickest and easiest to get me going down the right road, while Matthewspatrick, your article was a ton of information and I did not really have the time to dissect what I needed. You all contributed to this issue and I hope I fairly distribute the points. Thanks again guys, it is great to have this resource.
See below thread:
http://www.experts-exchang
HTH,
Daniel