Microsoft KB Archive/162075

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

Article ID: 162075

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q162075



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



SYMPTOMS
When you use the OutputTo method in Visual Basic for Applications to output a form or report module to a text file, 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 use the OutputTo method in Visual Basic for Applications to output form or report modules. Form or report modules are class modules that contain code that is local to the form or report. They do not appear in the Database window as standard modules do. You can output only modules that appear in the Database window with 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 form or report module and paste it into a word processing document; then you can 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 that appear on the Modules tab in the Database window.

Steps to Reproduce Behavior
 Open the sample database Northwind.mdb. Press CTRL+G to display the Debug window. 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.

