views:

56

answers:

4

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

+1  A: 

One can use MAPISession control in VB 6.0, so I suppose it will be available in VBA too.

Using the MAPI Controls

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)

Bogdan_Ch
I don't know about the specific control you're referring to, but not all ActiveX controls are compatible with Access. Also, if the control is not properly installed, it can completely break the Access app. Thus, it's better in Access to avoid anything other than the built-in ActiveX controls.
David-W-Fenton
A: 

CDO seems to work best. You can Google CDO.Message or check out this link: http://www.paulsadowski.com/WSH/cdo.htm

Jeff O
+1  A: 

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.

Oorang
vote +1 for Outlook Redemption, great toolset, especially Outlook spy!
Bogdan_Ch
+1  A: 

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.

David-W-Fenton