Send Email in Access VBA using SendObject Method

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.

Access_Conditional_Formatting_10

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.

http://www.tek-tips.com/faqs.cfm?fid=5230

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.

Object Name Value Description
acSendForm 2 Send a Form.
acSendModule 5 Send a Module.
acSendNoObject -1 (Default) Don’t send a database object.
acSendQuery 1 Send a Query.
acSendReport 3 Send a Report.
acSendTable 0 Send a Table.

You will be prompted to choose a file format to attach before sending the email.

Access_Conditional_Formatting_09

ObjectName Optional. Name of Object to include
OutputFormat Optional.
To Optional. Recipient’s Email address, use comma to separate email. For example, “abc@a.com, def@b.com”
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 receiver@hotmail.com and receiver2@hotmail.com.

DoCmd.SendObject , , , "receiver@hotmail.com,receiver2@hotmail.com",, , "This is the subject", "This is the content", False

The below code attach a table “enrollment” to receiver@hotmail.com

DoCmd.SendObject acSendTable ,"Enrollment" , , "receiver@hotmail.com,receiver2@hotmail.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

Send Email in Access VBA using CDO SendObject olMailItem

 Outbound References

https://msdn.microsoft.com/en-us/library/office/ff197046.aspx?f=255&MSPPError=-2147217396

 

Leave a Reply

Your email address will not be published.