ACC97: Can't Use OutputTo Method with Form or Report Modules

Last reviewed: August 29, 1997
Article ID: Q162075
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you try to output a form or report module to a text file using the OutputTo method in Visual Basic for Applications, you may receive the following error message:

   Microsoft Access
   Run-time error '2501'

   The OutputTo action was canceled.

   You used a method of the DoCmd object to carry out an action in Visual
   Basic, but then clicked Cancel in a dialog box. For example, you used
   the Close method to close a changed form, then clicked Cancel in the
   dialog box that asks if you want to save the changes you made to the
   form.

CAUSE

You cannot output form or report modules using the OutputTo method in Visual Basic for Applications. Form or report modules are class modules containing code that is local to the form or report. They do not appear in the Database window as standard modules do. Only modules that appear in the Database window can be output by using the OutputTo method.

RESOLUTION

When you use the OutputTo method, only output standard modules and class modules that are not associated with any form or report.

NOTE: A workaround for this is to copy all the code from the object module and paste it into a word processing document, and then save the word processing document as a text file.

MORE INFORMATION

The "OutputTo" topic in Microsoft Access Help states that you can output a module (standard or class) to a file in MS-DOS Text format. However, the only class modules that you can output are those which appear on the Modules tab in the Database window.

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Press CTRL+G to display the Debug window.

  3. Type the following in the Debug window:

         docmd.OutputTo acModule, "Employees", acFormatTXT, "C:\MyText.txt"
    

    Note that you receive the error message mentioned in the "Symptoms" section.

REFERENCES

For more information about using the OutputTo method to output a module, search the Help Index for "OutputTo," and then "OutputTo Method" or ask the Microsoft Access 97 Office Assistant.

Keywords          : kberrmsg kbprg
Version           : 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbdocerr


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.