This tutorial explains how to send Email in Access VBA using SendObject Method
Send Email in Access VBA using SendObject Method
To send email using SendObject Method is simple, because it does not require SMTP sever address and port number. When you run SendObject, whoever run the code will trigger to send email from its Outlook, instead of sending from a specific server email. It is a little bit strange because if you develop an application that sends confirmation email to user who have just signed up the system, the user will see he is sending himself a confirmation, not a confirmation sent from the server.
Note that before the email is sent, a security message will pop up, you must press “Allow” button to send the email.
To get rid of the above message to set Allow as default action, you may want to read the below article, but I have not tested it personally.
Syntax of SendObject Method
Docmd.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)
|ObjectType||Optional. To attach data of Access Object in the email message.
You will be prompted to choose a file format to attach before sending the email.
|ObjectName||Optional. Name of Object to include|
|To||Optional. Recipient’s Email address, use comma to separate email. For example, “email@example.com, firstname.lastname@example.org”|
|Cc||Optional. Cc Email address|
|Bcc||Optional. Bcc Email address|
|Subject||Optional. Subject of Email|
|MessageText||Optional. Message of Email|
|EditMessage||Optional. Set TRUE to edit message before send, FALSE to send without edit. Deafult is TRUE|
|TemplateFile||Optional. The path of HTML file to use as template|
Example of sending email using SendObject Method
The below code sends an email to email@example.com and firstname.lastname@example.org.
DoCmd.SendObject , , , "email@example.com,firstname.lastname@example.org",, , "This is the subject", "This is the content", False
The below code attach a table “enrollment” to email@example.com
DoCmd.SendObject acSendTable ,"Enrollment" , , "firstname.lastname@example.org,email@example.com",, , "This is the subject", "This is the content", False
Other methods to send email in Access VBA
There are two more alternatives in my another article, click the below link to read more