access parte 2

Page 28

Three Macro Recipes

or even a print-read PDF file. You specify the object you want to send, using the Object Type and Object Name arguments. • To email the current database object. This way gives you an infinitely flexible macro that can send off whatever data you’re currently looking at. The only limitation is that you need to know what type of object you’re planning to send, whether it’s a full table, a query that highlights important information, or a report with grouping and subtotals. Just set the Object Type argument accordingly, and leave Object Name blank. • To send an ordinary email message. To send a message, you simply leave both the Object Type and Object Name arguments blank. You can fill in the message using the Message Text property. This method is a handy way to let someone know when you’ve added some new data or finished a hefty editing job. Note: EMailDatabaseObject can send only a single database object at a time. If you want to send several database objects, you need to use EMailDatabaseObject several times. To send three reports, you need three email messages, with three attached files. In some cases, you may be able to get around this requirement by creating a clever query that fuses together all the information you want to send into one set of results. (For example, see union queries in page 205.)

The nicest thing about EMailDatabaseObject is that you can use it in an untrusted database, provided you follow one rule: Set the Edit Message argument to Yes. That way, when the macro runs, you get a final chance to review the message, change any text, and cancel it if you’re unhappy. But if you set Edit Message to No, then the EMailDatabaseObject action fires the message off without giving you a chance to step in. That behavior is considered risky, so Access doesn’t allow it in an untrusted database. The following macro converts two queries with sales information into Excel spreadsheets. It then mails them to the head honchos.

498

Action

Important Arguments*

Description

1. EMailDatabaseObject

Object Type: Query Object Name: MonthlySalesTotals Output Format: Excel Workbook (.xlsx) To: headhoncho@acme.com Subject: Monthly Update Message Text: Here are the most recent sales figures, straight from our macro-fied Access database. You’ll get the customer totals in a separate email. Edit Message: Yes

Sends an email message to headhoncho@acme.com, with the data from the MonthlySalesTotals query converted to an Excel workbook. The message subject and message text are set by the Subject and Message Text arguments. You have a chance to tweak them before the message is sent. Figure 15-18 shows this action.

Access 2010: The Missing Manual


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.