ACC2000: Modules.Count Returns Unexpected Results (201298)
The information in this article applies to:
This article was previously published under Q201298 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."
Modification Type: | Major | Last Reviewed: | 6/29/2004 |
---|
Keywords: | kbprb KB201298 |
---|
|