ACC97: Cannot Use RunCommand acCmdSaveModuleAsText in Code

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

SYMPTOMS

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

When you run code that contains the RunCommand method with the acCmdSaveModuleAsText constant, you may receive the following error message:

   The command or action 'SaveModuleAsText' isn't available now.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.

CAUSE

Microsoft Access cannot save a code module while code is running.

RESOLUTION

The following two methods describe how to save a code module programmatically.

Method 1: Using the OutputTo method

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  3. Type the following procedure:

          Function SaveMod()
    
             DoCmd.OutputTo acOutputModule, "Utility Functions"
          End Function
    
    

  4. To test this function, type the following line in the Debug window, and then press ENTER.

           ?SaveMod()
    

  5. The Output To dialog box appears and prompts you for the file name and file type to save the Utility Functions module.

Method 2: Using the RunCommand Macro Action

  1. Open the sample database Northwind.mdb.

  2. Create the following new macro called SaveMod:

          Macro Name      Action
          --------------------------
          SaveMod         OpenModule
                          RunCommand
    
          SaveMod Actions
          ---------------------------------
          OpenModule
             Module Name: Utility Functions
             Procedure Name: <Leave blank>
          RunCommand
             Command: SaveModuleAsText
    
    

  3. Save the macro, and then run it.

  4. The Save As Text dialog box appears and prompts you for the file name and file type to save the Utility Functions module.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following line in the Declarations section if it is not already there:

          Option Explicit
    

  3. Type the following procedure:

          Function SaveModFail()
    
             DoCmd.OpenModule "Utility Functions"
             DoCmd.RunCommand acCmdSaveModuleAsText
          End Function
    
    

  4. To test this function, type the following line in the Debug window, and then press ENTER.

           ?SaveModFail()
    

    Note that you receive the following error message:

          The command or action 'SaveModuleAsText' isn't available now.
    

REFERENCES

For more information about the OutputTo method, search the Help Index for "OutputTo method."

For more information about the RunCommand method, search the Help Index for "RunCommand method."

Keywords          : kberrmsg kbprg PgmHowTo PgmObj MdlOthr
Version           : 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : Info_Provided


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


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.