Hi,
I am trying to send e-mail from MS Access using VBA but cannot use the sendobject function as this doesn't support external file attachment.
Does anyone know how I can do this?
Thanks
Hi,
I am trying to send e-mail from MS Access using VBA but cannot use the sendobject function as this doesn't support external file attachment.
Does anyone know how I can do this?
Thanks
One can use MAPISession control in VB 6.0, so I suppose it will be available in VBA too.
Another way is to use Outlook object model, but it will require MS Outlook to be installed. However most users that have Access, usually have Outlook on their desktops too. See How to automate Outlook by using Visual Basic
And yet another one decision - you can use .NET (VB.NET for exmaple) to write a very small component that will use System.Net.Mail to compose and send SmtpMail. For you as VBA developer it will not be very hard. You can write one class with a single function SendEmail. Then you can expose this class to COM, see Exposing .NET Framework Components to COM Then you will have an ActiveX DLL that you can call from your VBA project (using CreateObject("") and so on)
CDO seems to work best. You can Google CDO.Message or check out this link: http://www.paulsadowski.com/WSH/cdo.htm
If you are going to use the CDO solution (http://www.paulsadowski.com/WSH/cdo.htm) then you should be aware that as of Office 2007 CDO is not bundled with Outlook anymore. If you are going to use a CDO solution you will need to download the CDO library here and make sure that said library is also installed on any machine you plan on deploying your solution to. Another alternative would be Outlook Redemption. But either will work fine. And both will require deployment.
For an omnibus answer to this question (emailing from Access), see Tony Toews's Access EMail FAQ. Tony recommends doing it directly via Winsock as this avoids any need to worry about versions of components like CDO or distributing DLLs or installing ActiveX controls. The downside, as Tony admits, is that it's substantially more code-intensive.