Solved

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

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

803 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