473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to use VBA to add Attachments to Emails

16
Hi

I have a database where visit reports are attached to individual records. Field Name: "KAM Visit Report"

I want to have a macro button that will send an email with the report as an attachment.

Can I do this using the DoCmd coding?

Thanks
Jun 29 '10 #1
2 5710
jimatqsi
1,271 Expert 1GB
Be prepared for a very dark time in your life. No, just kidding, it's not that bad.

You will want to read about CDO emails versus using Outlook to send your emails. If you route the emails through Outlook, then it shows up in your Outlook Sent outbox and/or sent folder. But there's this goofy security warning message that pops up creating headaches, but thee's a little fix program for that, and maybe I'm forgetting some other little issues.

If you use CDO you may have to get with the network security guy to open a port for you and you'll have to let him know what user will be sending the CDO emails. It's not a good idea to open a port for just any/every user to do that.

I strongly prefer the CDO email method. Outlook was such a pain when I was trying to do it that way. Anyway, there's a lot of good discussion about the details of getting this done on bytes.com See these threads:

http://bytes.com/topic/access/answer...il-attachments

http://bytes.com/topic/access/answer...do-attachments

http://bytes.com/topic/access/answer...endmessage-cdo

One of these discussions mentions the lack of any notification that the mail was sent. I just include a .bcc so that all the cdo emails I send go to a mailbox where I can see what was sent and when. The .sender you use may get bounce notifications sometimes if a bad address shows up or a mailbox is full.

Jim
Jun 29 '10 #2
patjones
931 Expert 512MB
I'm not sure about email options other than Outlook, and so you should probably thoroughly look into Jim's CDO suggestions.

You can also look into the DoCmd.SendObject method...the VBA help page on SendObject is very thorough and it is a few minutes of reading that is well worth your time. This is a good option if you have not previously exported the report to a file somewhere outside of Access.

For a third possibility, if you want more fine-grained control over the process, the following will work with Outlook. Make sure you set a reference to the Microsoft Office Outlook library in the VBA window by going Tools > References... and then scrolling down to Microsoft Office Outlook and check marking it.

Expand|Select|Wrap|Line Numbers
  1. Dim olApp As New Outlook.Application, olMail As Outlook.MailItem
  2. Set olMail = olApp.CreateItem(olMailItem)
  3.  
  4. With olMail
  5.     .To = strSendTo
  6.     .Subject = strSubject
  7.     .ReadReceiptRequested = False
  8.     .Body = strBody
  9.     .Attachments.Add strAttachFile
  10.  
  11.     .Send
  12. End With
  13.  
  14. Set olApp = Nothing
  15. Set olMail = Nothing

In this code, the various strings are pieces of information that I set elsewhere in the code, such as the recipient email address, the subject, etc.

Also, strAttachFile is the path to whatever you want to attach to the email. This implies that you need to have previously saved the report as an external file first, which may or may not be your situation.

Pat
Jun 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: paii, Ron | last post by:
How do I setup a email with attachment for preview but require the user to push the SEND button in Outlook. I have the following function but it sends the email without the sender ever seeing it. ...
1
by: Peter Wullems | last post by:
I use C# to parse incoming emails for a predefined type and structure of message content and construct replies automatically, attach a file and place the generated emails in the drafts folder. ...
8
by: Ajit | last post by:
Is there anyway to move attachments from a incoming email into a specified folder using System.Web.Mail ? has anyone done this ? Any help is appreciated.
4
by: tomer.ha | last post by:
Hi there, I'm new to Python, but know other scripting and programming languages. I want to develop a script which will receive emails with attachments from my POP3 account, perform certain...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
1
by: PhilD | last post by:
My C#.NET console app checks a public folder every 24 hours for incoming emails. For each unread email in the folder, it copies any attachments to the network, then loads the contents of these files...
5
by: sck10 | last post by:
Hello, I am working on a new project where I need to: 1. open an email and then create an xml file from the email 2. open the xml file and parse the information. I would like to be able to do...
0
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
130
by: Gianni Mariani | last post by:
Attached example CPP files makes it easier to post code and extract code from posts. It's unimaginable at this time where virtually any news reader is capable of dealing with attachments to stick...
0
by: benjaminwf | last post by:
Hello - this is my 1st question. I have created an Access database that pushes emails with attachments (should be 1 attachment per email). My attachments are accumulating rather than 1 attachment...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.