ACC97: New Module in Microsoft Access 97 Not Saved If Empty

ID: Q175218


The information in this article applies to:
  • Microsoft Access 97


SYMPTOMS

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

When you create a module in Microsoft Access 97, you are not prompted to save the module if you have not entered data into the module. In Microsoft Access 95, you are prompted to save the module even though the module is empty.

This behavior occurs in Microsoft Access 97 regardless of whether you are creating the module with code or you are creating the module manually.


CAUSE

The module must contain data before it can be saved.


RESOLUTION

When you want to create a module that will not have any code, add a procedure or function to the module before you save it. This will ensure that the module is saved. For example, the following procedure will create a new module, add a procedure to the module, and then save the module.


   Sub CreateNewModule()

      Dim MyMod As Module
      Dim MyStr As String

      DoCmd.RunCommand acCmdNewObjectModule  ' Create new module.

      MyStr = "Sub Test2()" & vbCrLf         ' Create text for the module.

      MyStr = MyStr & Space$(4) & "MsgBox " & Chr$(34) & "test2" & _
      Chr$(34) & vbCrLf

      MyStr = MyStr & "End Sub"

      Set MyMod = Modules("Module3")         ' Give module a name.

      MyMod.InsertText MyStr                 ' Insert text into the module.

      DoCmd.Close acModule, "Module3", acSaveYes   ' Close and save module.

      End Sub 


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. In Microsoft Access 97, create a module and type the following line in the Declarations section, if it is not already there:
    Option Explicit


  2. Type the following procedure in the module:
    
          Sub CreateModule()
    
            DoCmd.RunCommand acCmdNewObjectModule
    
            DoCmd.Close acModule, "Module2", acSaveYes
    
          End Sub 


  3. Save the module as Module1.


  4. Press CTRL+G to open the Debug window.


  5. To test this procedure, type the following line in the Debug window, and then press ENTER:
    CreateModule
    Note that the Module2 is not saved in the Database window.



REFERENCES

For more information about creating modules, search the Help Index for "modules, overview," or ask the Microsoft Access 97 Office Assistant.

Additional query words: not dirty

Keywords : MdlGnrl
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: December 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.