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 "Myemailaddress es" 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.
Emails from access
Collapse
X
-
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,
Code:Dim strTo as String Dim i as Integer While i < myListBox.ListCount If myListBox.selected(i) strTo = strTo & myListBox.ItemData(i) & "; " End If i = i + 1 Wend objMailItem.To = strTo
-
Emails from access
Thanks Chip R. for the response.
I currently have an access query that populates the "MyEmailAddress es" query, which in turn is used in the SendMail module,
i.e. Set MailList = db.OpenRecordse t("MyEmailAddre sses")
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 "MyEmailAddress es" 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 FilesComment
-
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.Comment
Comment