ACC2000: Cannot Use RunCommand acCmdSaveModuleAsText in Code

ID: Q200646


The information in this article applies to:

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


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.


CAUSE

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


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:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
    Function SaveMod()
       DoCmd.OutputTo acOutputModule, "Utility Functions"
    End Function 
  6. To test this function, type the following line in the Immediate Window, and then press ENTER:


  7. 
    ?SaveMod() 
  8. The Output To 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:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5. 
    Function SaveModFail()
       DoCmd.OpenModule "Utility Functions"
       DoCmd.RunCommand acCmdSaveModuleAsText
    End Function 
  6. 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:


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


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.

Additional query words:


Keywords          : kberrmsg kbprg MdlOthr PgmObj 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: May 13, 1999