Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: Cannot Use RunCommand acCmdSaveModuleAsText in Code


View products that this article applies to.

This article was previously published under Q200646
Moderate: Requires basic macro, coding, and interoperability skills.

↑ Back to the top


Symptoms

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.

↑ Back to the top


Cause

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

↑ Back to the top


Resolution

You can use the following method to save a code module programmatically:
  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 Immediate 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.

↑ Back to the top


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 Immediate window, and then press ENTER:
    ?SaveModFail()
    						
    Note that you receive the following error message:
    The command or action 'SaveModuleAsText' isn't available now.

↑ Back to the top


References

For more information about the OutputTo method, click Microsoft Access Help on the Help menu, type OutputTo in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about the RunCommand method, click Microsoft Access Help on the Help menu, type RunCommand method in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB200646, kbprb, kbprogramming, kberrmsg

↑ Back to the top

Article Info
Article ID : 200646
Revision : 1
Created on : 12/12/2002
Published on : 12/12/2002
Exists online : False
Views : 247