If you are an Access Developer then at a point you could have a situation when you need to send an email through Microsoft Outlook. The article provided you here, will guide you to resolve this completely. This article is explained through an example here:-
First, Create a table in the database, which contain Email-IDs; shown below in Fig:- 1.1.
create a form with a button . When the user will click on to the button it will fetch all the Email-IDs from the table and will pop up Microsoft Outlook Window to send mail to the recipients, that are present into the table. Fig:-1.2 shows the form.
When the user will click onto the button a message box will appear, asking for the “Subject” of the Mail as shown below in Fig:- 1.2.1.
When you will provide subject and click “OK”. A new message box will appear as shown in Fig: - 1.2.2, asking for “Message Body”.
When you will click “Ok” button, final Microsoft Outlook Window will appear with the entered “Subject” and the “Message Body”, As shown in Fig:- 1.3.
Here is the VBA Code provided for sending Email Via Ms-Access Using Outlook :-
Public Function SendEMail()
Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim MyBodyText As String
Subjectline$ = InputBox$("Please enter the subject line for this mailing.", "We Need A Subject Line!")
If Subjectline$ = "" Then
MsgBox "No subject line, no message." & vbNewLine & vbNewLine & "Quitting...", vbCritical, "E-Mail Merger"
BodyFile$ = InputBox$("Please enter the filename of the body of the message.", "We Need A Body!")
If BodyFile$ = "" Then
MsgBox "No body, no message." & vbNewLine & vbNewLine & "Quitting...", vbCritical, "I Ain??t Got No-Body!"
Set MyOutlook = New Outlook.Application
Set db = CurrentDb()
Set MailList = db.OpenRecordset("TBL_Emails")
Do Until MailList.EOF
Set MyMail = MyOutlook.CreateItem(olMailItem)
MyMail.To = MailList("Email_ID")
MyMail.Subject = Subjectline$
MyMail.Body = BodyFile$
Set MyMail = Nothing
Set MailList = Nothing
Set db = Nothing
Private Sub SendMail_Click()
It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.