Microsoft KB Archive/299016

= How to fax from Access by using the SendObject command in Access 2002 =

Article ID: 299016

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q299016





For a Microsoft Access 97 version of this article, see 145787.



For a Microsoft Access 2000 version of this article, see 231797.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Advanced: Requires expert coding, interoperability, and multiuser skills.

IN THIS TASK

 * SUMMARY
 * Outlook e-mail security
 * Using the SendObject method
 * Creating a macro
 * Creating a Visual Basic procedure
 * REFERENCES



SUMMARY
This article describes how to create a macro and a Visual Basic procedure to fax a report from Microsoft Access. The examples assume that you have Microsoft Outlook, Microsoft Fax, and a fax modem installed, and that they are working.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. back to the top

Outlook e-mail security
The following code may not work correctly if you have installed the Outlook E-mail Security Update. For additional information about this update for Outlook 2000, click the following article number to view the article in the Microsoft Knowledge Base:

262631 OL2000: Information About the Outlook E-mail Security Update

For additional information about this update for Outlook 98, click the following article number to view the article in the Microsoft Knowledge Base:

262617 OL98: Information About the Outlook E-mail Security Update

If your fax does not have correct formatting, you may want to change your default e-mail editor to Microsoft Word.

For more information about the Outlook 2002 e-mail security features and how those features can affect custom solutions, click the following article number to view the article in the Microsoft Knowledge Base:

290500 Description of the developer-related e-mail security features in Outlook 2002

back to the top

Using the SendObject method
The examples that are used in this article refer to the sample database Northwind.mdb. The examples show you how to create a macro and a Visual Basic procedure to fax a report by using Microsoft Fax. However, you can also use an Access project (.adp) file for faxing information.

When you use the SendObject method in Microsoft Access, you must have a messaging application, such as Microsoft Outlook, that supports the Microsoft Mail Applications Programming Interface, also known as MAPI.

If Microsoft Outlook 2002 is installed on your computer, and you try to run the macro or the code to fax a report by using Microsoft Fax, you may not be able to fax the report successfully.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

319820 OL2002: You Receive an NDR When You Use a Simple MAPI Program to Send a Message

If Outlook is running when you try to run the macro or the code, you may receive a message that is similar to the following:

The file C:\Windows\Application Data\Microsoft\Outlook\Outlook.ost is in use and could not be accessed. Close any application that is using this file, and then try again.

If you receive this message, close Outlook and then run the code again.

If you have an electronic mail application that uses the Vendor Independent Mail (VIM) protocol, you have to install and to setup the dynamic-link library that is named Mapivim.dll. Mapivim.dll converts MAPI mail messages to the VIM protocol. Now you can send Microsoft Access objects to the VIM mail application.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

back to the top

Creating a macro
This example uses the SendObject action to fax the Catalog report to a single fax number.  Open the sample database Northwind.mdb. Open the Catalog report in Design view. On the File menu, click Page Setup. In the Page Setup dialog box, click the Page tab. In the Printer for Catalog option group, click Use Specific Printer, and then click Printer. In the Name list, click Microsoft Fax, and then click OK.</li> In the Page Setup dialog box, click OK.</li> Save the Catalog report, and then close it.</li>  Create the following macro named SendFax: <pre class="fixed_text">   Macro name   Action SendFax     SendObject

Action Arguments Object type: Report Object name: Catalog Output format: Rich Text Format To: [Fax: +1 (###) ###-####] (where (###) ###-#### is the fax number) Note You do not have to include the hyphen in the previous fax number for this to work.

</li> Run the macro to fax the report.</li></ol>

back to the top

Creating a Visual Basic procedure
Note The sample code in this article uses Microsoft Data Access Objects. For this code to run correctly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected. This example shows you how to fax the Invoice report to each customer in the Customers table. <ol> Open the sample database Northwind.mdb.</li> Open the Invoice report in Design view.</li> On the File menu, click Page Setup.</li> In the Page Setup dialog box, click the Page tab.</li> In the Printer For Invoice option group, click Use Specific Printer, and then click Printer.</li> In the Name list, click Microsoft Fax, and then click OK.</li> In the Page Setup dialog box, click OK.</li>  Set the OnOpen property of the report to the following event procedure: Me.Filter = strInvoiceWhere </li> Save the report, and then close it.</li> In the Database window, click Modules, and then click New.</li>  Put the following code in the module.

Note If you plan to change this example and put the code behind a form, leave the line &quot;Public strInvoiceWhere As String&quot; in a standard module. Option Explicit

Public strInvoiceWhere As String '**************************************************************** 'This function will walk through the Customers table and fax the 'Invoice report that is filtered by the CustomerID field by using 'MS Fax through the MS Access SendObject. ' 'This function assumes that the Invoice report has the default printer 'set to MS Fax, and that the MS Fax driver is installed correctly. '**************************************************************** Function FaxInvoices Dim dbsNorthwind As DAO.Database Dim rstCustomers As DAO.Recordset

Set dbsNorthwind = CurrentDb Set rstCustomers = dbsNorthwind.OpenRecordset(&quot;Customers&quot;, _       dbOpenDynaset)

If MsgBox(&quot;Do you want to fax invoices&quot; & Chr(13) & _       &quot;to all customers who are using Microsoft Fax?&quot;, 4) = 6 Then With rstCustomers Do Until .EOF 'Create the Invoice report Filter 'that is used by the Report_Open event. strInvoiceWhere = &quot;[CustomerID] = '&quot; & ![CustomerID] & &quot;'&quot; DoCmd.SendObject acReport, &quot;Invoice&quot;, acFormatRTF, _ &quot;[fax: &quot; & ![Fax] & &quot;]&quot;,, , , , False .MoveNext Loop End With End If

rstCustomers.Close End Function </li> <li> To test this function, type the following line in the Immediate window, and then press ENTER: ? FaxInvoices </li></ol>

To improve performance, you can choose to delay faxing to a time that is less busy. You can also change the rendering engine. Rich Text Format (RTF) messages sent to Microsoft Fax have to be rendered. The rendering process uses the application that is associated with .rtf documents. For example, you may have installed Microsoft Word 2000. That means that Microsoft Word 2000 is the rendering application. Microsoft WordPad is a smaller and faster application. If you want to send many fax documents, you can change the .rtf association from Microsoft Word 2000 to WordPad.

To change the association for .rtf documents to WordPad, follow these steps:
 * 1) Click Start, click Run, type Winfile, and then click OK.
 * 2) On the File menu, click Associate in File Manager.
 * 3) In the Associate dialog box, type rtf under Files with Extension.
 * 4) Click Browse.
 * 5) Locate WordPad.exe in C:\Program Files\Accessories, and then click OK.
 * 6) Quit File Manager.

To change the time to send a fax, follow these steps:
 * 1) Click Start, point to Settings, and then click Control Panel.
 * 2) Double-click Mail And Fax.
 * 3) In The following information services are set up in this profile box, click Microsoft Fax, and then click Properties.
 * 4) In the Time to Send box, click Specific Time, type a time in the Time box, and then click OK.
 * 5) Close the Mail And Fax box.

back to the top

<div class="references_section">