ACC2000: Modules.Count Returns Unexpected Results

ID: Q201298


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

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


SYMPTOMS

In Microsoft Access 97, Modules.Count returns the number of currently open Visual Basic for Applications modules; however, in Microsoft Access 2000, Modules.Count returns the number of modules last opened in the Visual Basic Editor, even if you have not opened the Editor in the current session.


CAUSE

In order to open a module in Microsoft Access 2000, you must use the Visual Basic Editor. One function of the Visual Basic Editor is to remember what modules were opened in the previous session and have those modules open and arranged in the same manner the next time that you run the Visual Basic Editor. Consequently, even though the Visual Basic Editor may be closed, Modules.Count may not return 0.


RESOLUTION

If your goal is to see if any modules are currently open, you can instead check to see if the Visual Basic Editor is visible. To demonstrate, follow these steps:

  1. Open the sample database Northwind.mdb.


  2. Create a new form not based on any table or query and add a command button.


  3. Set the OnClick property of the command button to the following event procedure:


  4. 
    Private Sub Command0_Click()
       MsgBox VBE.MainWindow.Visible
    End Sub 
  5. Close the Visual Basic Editor.


  6. Save the new form and view it in Form view.


  7. Click the command button. Note that you get a message box that says "False."


  8. Click OK on the message box and close the form.


  9. On the Tools menu, point to Macro, and then click Visual Basic Editor.


  10. Minimize the Visual Basic Editor (but do not close it).


  11. Open the new form again, and click the command button.

    Note that the message box now says "True."



MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.


  2. Create a new form not based on any table or query and add a command button.


  3. Set the OnClick property of the command button to the following event procedure:


  4. 
    Sub Command0_Click()
       MsgBox Application.Modules.Count
    End Sub 
  5. Save the form.


  6. In the Visual Basic Editor, close the module associated with the form. At this point, no modules are open in the Visual Basic Editor.


  7. From the list of projects, open the Startup and Utility Functions modules.


  8. Close the Visual Basic Editor and quit Microsoft Access.


  9. Open the sample database Northwind.mdb.


  10. Open the form you've been using and click the command button.

    Note that the message box says "3".

    If you repeat these same steps in Microsoft Access 97, the message box would say "0."


Additional query words: prb

Keywords : kbdta
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbprb


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