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
Solved

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

Posted on 2014-09-15
3
213 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
  • 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update query 4 25
UK Date format in MS Access 4 21
Access form for login using active directory 6 21
error in For & Next statements 4 23
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

856 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