Applies ToAccess for Microsoft 365 Access 2024 Access 2021 Access 2019 Access 2016

You can use the EMailDatabaseObject macro action in Access desktop databases to include the specified Access datasheet, form, report, or module in an electronic mail message, where it can be viewed and forwarded.

Note: This action will not be allowed if the database is not trusted.

Settings

The EMailDatabaseObject action has the following arguments.

Action argument

Description

Object Type

The type of object to include in the mail message. Click Table (for a table datasheet), Query (for a query datasheet), Form (for a form or form datasheet), Report, Module, or Data Access Page, Server View, Stored Procedures, or Function in the Object Type box in the Action Arguments section of the macro design window. You can't send a macro. If you want to include the active object, select its type with this argument, but leave the Object Name argument blank.

Object Name

The name of the object to include in the mail message. The Object Name box shows all objects in the database of the type selected by the Object Type argument. If you leave both the Object Type and Object Name arguments blank, Access sends a message to the mail application without any database object.

If you run a macro containing the EMailDatabaseObject action in a library database, Access looks for the object with this name first in the library database, then in the current database.

Output Format

The type of format you want used for the included object. The list of formats you can select from will change depending on what you select for the Object Type argument. Available formats may include Excel 97 - Excel 2003 Workbook (*.xls), Excel Binary Workbook (*.xlsb), Excel Workbook (*.xlsx), HTML (*.htm, *.html), Microsoft Excel 5.0/95 Workbook (*.xls), PDF Format (*.pdf), Rich Text Fomat (*.rtf), Text Files (*.txt), or XPS Format (*.xps). in the Output Format box. Modules can be sent only in text format. Data access pages can only be sent in HTML format. If you leave this argument blank, Access prompts you for the output format.

To

The recipients of the message whose names you want to put on the To line in the mail message. If you leave this argument blank, Access prompts you for the recipients' names.

Separate the recipients' names you specify in this argument (and in the Cc and Bcc arguments) with a semicolon (;) or with the list separator set on the Number tab of the Regional Settings Properties dialog box in Microsoft Windows Control Panel. If the mail application can't identify the recipients' names, the message isn't sent and an error occurs.

Cc

The message recipients whose names you want to put on the Cc ("carbon copy") line in the mail message. If you leave this argument blank, the Cc line in the mail message is blank.

Bcc

The message recipients whose names you want to put on the Bcc ("blind carbon copy") line in the mail message. If you leave this argument blank, the Bcc line in the mail message is blank.

Subject

The subject of the message. This text appears on the Subject line in the mail message. If you leave this argument blank, the Subject line in the mail message is blank.

Message Text

Any text you want to include in the message in addition to the database object. This text appears in the main body of the mail message, after the object. If you leave this argument blank, no additional text is included in the mail message. If you leave the Object Type and Object Name arguments blank, you can use this argument to send a mail message without a database object.

Edit Message

Specifies whether the message can be edited before it's sent. If you select Yes, the electronic mail application starts automatically, and the message can be edited. If you select No, the message is sent without the user having a chance to edit the message. The default is Yes.

Template File

The path and file name of a file you want to use as a template for an HTML file. The template file is a file containing HTML tags.

Remarks

The object in the mail message is in the selected output format. When you double-click the object, the appropriate software starts with the object opened.

The following rules apply when you use the EMailDatabaseObject action to include a database object in a mail message:

  • You can send table, query, and form datasheets. In the included object, all fields in the datasheet look as they do in Access, except fields containing OLE objects. The columns for these fields are included in the object, but the fields are blank.

  • For a control bound to a Yes/No field (a toggle button, option button, or check box), the output file displays the value –1 (Yes) or 0 (No).

  • For a text box bound to a Hyperlink field, the output file displays the hyperlink for all output formats except MS-DOS text (in this case, the hyperlink is just displayed as normal text).

  • If you send a form in Form view, the included object always contains the form's Datasheet view.

  • If you send a report, the only controls that are included in the object are text boxes and (in some cases) labels. All other controls are ignored. Header and footer information is also not included. The only exception to this is that when you send a report in Excel format, a text box in a group footer containing an expression with the Sum function is included in the object. No other control in a header or footer (and no aggregate function other than Sum) is included in the object.

  • Subreports are included in the object.

  • When you send a datasheet, form, or data access page in HTML format, one .html file is created. When you send a report in HTML format, one .html file is created for each page in the report.

To run the EMailDatabaseObject action in a Visual Basic for Applications (VBA) module, use the SendObject method of the DoCmd object.

image

The following link was provided by Luke Chung. Luke is the founder and president of FMS, Inc., a leading provider of custom database solutions and developer tools.

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.