Connecting Tech Pros Worldwide Help | Site Map

Emails from access

Newbie
 
Join Date: Oct 2009
Posts: 18
#1: 2 Weeks Ago
I found a really neat URL on the web entitled, "How to Send E-Mail From MS Access using Outlook" and decided to test it with my database. I’ve gotten so far with it, but I have an additional question and didn't get a response back from the site owner, so I wondered if maybe someone else knew how to do this. Is there a way to pull the email addresses from an Access table or form based on the ones that are chosen or “enabled”? For example, I have an access form that requires you to choose one person each from a series of combo boxes which have the employees only listed by their job title. When a new project comes in, you select a person from each box to “assign” to the project. Then I display each assignee’s email address in a text box. Now I want to take just the email addresses of those chosen for that project and put them as the recipients in an email to send. I've attached the SendMail module as it works now, which I got from that article. As it seems to work now, it includes all items from the list. The "Myemailaddresses" code for the query pulls the person's name and their email address. I want to pull just specific ones and input them into the recipient field. Thanks.
Attached Files
File Type: txt SendMailFunctiontext.txt (3.6 KB, 11 views)
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,164
#2: 2 Weeks Ago

re: Emails from access


You just need to set the MailItem's .To property. I would loop through the chosen recipients and add their addresses to a string. For example,
Expand|Select|Wrap|Line Numbers
  1. Dim strTo as String
  2. Dim i as Integer
  3.  
  4. While i < myListBox.ListCount
  5.     If myListBox.selected(i)
  6.         strTo = strTo & myListBox.ItemData(i) & "; "
  7.     End If
  8.     i = i + 1
  9. Wend
  10.  
  11. objMailItem.To = strTo
Newbie
 
Join Date: Oct 2009
Posts: 18
#3: 2 Weeks Ago

re: Emails from access


Thanks Chip R. for the response.
I currently have an access query that populates the "MyEmailAddresses" query, which in turn is used in the SendMail module,
i.e. Set MailList = db.OpenRecordset("MyEmailAddresses")

I've created a MailForm, on which i have 5 combo boxes, which allow a user to pick one reviewer from each job title to assign to the project (not every project needs one from each job title, but you would just skip that combo box).
Once a user is selected, I display their email address in a text box field.
I then want to take ONLY the email addresses selected on this form and put them into the query that is used above by the SendMail module.
The current "MyEmailAddresses" file includes all reviewers selected.

How can I get my query to only select the value returned from the form's text box for each of the 5 combo box selections?
I've used "Like" in the Criteria of other queries to pull the data from combo box selections, but I'm not exactly sure how the Like statement would work here when I want to pull multiple values of the same type from multiple boxes.
I've attached a screenshot of my Mail Form and the table that it pulls from.

For the time being I have all fields of the email set to my email address to avoid it sending to the real recipients during testing.
I know that part of it works because the correct email address being displayed in the text box on the form.
Thanks.
Attached Files
File Type: zip MailForm&TableExample.zip (27.5 KB, 6 views)
Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,164
#4: 2 Weeks Ago

re: Emails from access


The SendMail function is well commented and easy to understand. I would create a new version specific to your form and put it in the form module. There is no reason to use a recordset to get the email addresses if you already have them on the form.
Reply