Microsoft Access VBA Programming for the Absolute Beginner
Exports a datasheet, form, report, module, or Data Access Page to one of four different formats and sends it in an email as an attachment.
Syntax
DoCmd.SendObject [ObjectType][, ObjectName][, OutputFormat][, To][, Cc][, Bcc][, Subject][, MessageText][, EditMessage][, TemplateFile]
with the following parameters:
ObjectType
One of the following AcSendObjectType constants: acSendDataAccessPage, acSendForm, acSendModule, acSendNoObject (the default value, which sends an email without including an object), acSendQuery, acSendReport, and acSendTable.
ObjectName
The name of the object of type ObjectType to send, or (if omitted) the active object.
OutputFormat
A constant defining the output format of the exported object. Supported values include acFormatHTML, acFormatXLS, acFormatTXT, and acFormatRTF. If omitted, the Send dialog box opens to prompt for an output format.
To, Cc, and Bcc
Strings indicating the recipients, copied recipients, and blindly copied recipients of the email. Multiple recipients can be separated by a semicolon or by the list separator defined for numbers in the Control Panel’s Regional Settings applet.
Subject
A String specifying the subject line of the email.
MessageText
A string containing the text of the email.
EditMessage
A Boolean determining whether the mail application should immediately open the message for editing after the SendObject method completes. The default is True.
TemplateFile
The path and name of a template to be used for an output HTML file.
Example
The following code sends a variety of Access objects in a number of formats:
Public Sub SendEmails() Dim strTo As String, strSubject As String, strText As String strTo = "ron@howlingwolfconsulting.com" strSubject = "The Customer List" strText = "Per your request." DoCmd.SendObject acSendTable, "tblCustomer", acFormatHTML, _ strTo, , , strSubject, strText, False DoCmd.SendObject acSendReport, "rptCustomerList", acFormatHTML, _ strTo, , , strSubject, strText, False DoCmd.SendObject acSendQuery, "qryCustomer", acFormatRTF, _ strTo, , , strSubject, strText, False DoCmd.SendObject acSendForm, "frmCustomer", acFormatHTML, _ strTo, , , strSubject, strText, False End Sub
Comments
-
The acSendModule type can only be sent in acFormatTXT, and acSendDataAccessPage can only be sent in acSendHTML.
-
Names or email addresses must be in a format recognized by the email application.
Категории