Solved

How can I email users from multiple contact drop down lists on same form

Posted on 2014-09-15
3
223 Views
Last Modified: 2014-10-08
Hello,

Access 2010
I have a form that has multiple dropdown lists (same user contacts in all) that are then displayed on the form as team members for a task.  I would like to send an email notification to those user when they are selected for a task. There is a Save and Close button that is clicked when the form is complete.

Thank you in advance!
1212pro
0
Comment
Question by:1212pro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Sheils earned 500 total points
ID: 40323870
This can be done by using vba coding on the after update event of the form.

Create a module and paste in the following code

Public Function SendEnail(strRecipient as String,strSubject as String,strBodyText as string)

Dim olApp As Object
Dim objMail As Object

On Error Resume Next 'Keep going if there is an error

Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance of Outlook

End If

'Create e-mail item
Set objMail = olApp.CreateItem(olMailItem)

With objMail

'Set body format to HTML
.BodyFormat = olFormatHTML
.To = strRecipient
.Subject = strSubject
.HTMLBody = strBodyText
.send

End With

MsgBox "Email Send successfully"

End Function

Open in new window


Then call the send email function from the afterupdate event of your form.
0
 

Author Comment

by:1212pro
ID: 40323977
Hello Sheils,
I'm pretty much a novice at this.  How will outlook know where to look for the email addresses of the team members?  Here are some screen shots of what I have.Team-1.docx
0
 
LVL 16

Expert Comment

by:Sheils
ID: 40324068
You need a table t store the name and email address of all your contacts.

Let's call that tblContact and it will have the following fields:

fldContactId, fldContactName,fldContactEmail

Then you can use the following code to call the sendemail function

Private Sub Form_AfterUpdate()

Dim strEmailAddress as string
Dim strSubject as String
Dim strBodyText as String

strEmailAddress=DLookup("fldContactEmail","tblContact ","fldContactId=" & Me.cboDelegatedTo)
strSubject ="New Task"
strBodyText ="You have a new text"

Call SendEnail(strEmailAddress,strSubject,strBodyText)

End Sub

Open in new window


This code is just to send email to the person in the delegated to combo. I assume that your combo box is bounded to the id of that person which should come from the contact table.

Once you've got that working and understand how the code works I will help you expand it to also send email to all team members. However, I note that it will be much easier to use a team member table and then use a teammember subform on your main form. In addition to making your code easier it will also give you the flexibility of have bigger teams if necessary.

The tblTeamMember should have the following fields:

fldControlNumber,fldTeamMember (lookup fldContactId in tblContact).
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question