ACC2000: Modules.Count Returns Unexpected Results
ID: Q201298
|
The information in this article applies to:
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:
- Open the sample database Northwind.mdb.
- Create a new form not based on any table or query and add a command button.
- Set the OnClick property of the command button to the following event procedure:
Private Sub Command0_Click()
MsgBox VBE.MainWindow.Visible
End Sub
- Close the Visual Basic Editor.
- Save the new form and view it in Form view.
- Click the command button. Note that you get a message box that says "False."
- Click OK on the message box and close the form.
- On the Tools menu, point to Macro, and then click Visual Basic Editor.
- Minimize the Visual Basic Editor (but do not close it).
- Open the new form again, and click the command button.
Note that the message box now says "True."
MORE INFORMATION
Steps to Reproduce Behavior
- Open the sample database Northwind.mdb.
- Create a new form not based on any table or query and add a command button.
- Set the OnClick property of the command button to the following event procedure:
Sub Command0_Click()
MsgBox Application.Modules.Count
End Sub
- Save the form.
- In the Visual Basic Editor, close the module associated with the form. At this point, no modules are open in the Visual Basic Editor.
- From the list of projects, open the Startup and Utility Functions
modules.
- Close the Visual Basic Editor and quit Microsoft Access.
- Open the sample database Northwind.mdb.
- 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