Microsoft KB Archive/201298

= ACC2000: Modules.Count Returns Unexpected Results =

Article ID: 201298

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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."</li> Click OK on the message box and close the form.</li> On the Tools menu, point to Macro, and then click Visual Basic Editor.</li> Minimize the Visual Basic Editor (but do not close it).</li> Open the new form again, and click the command button.

Note that the message box now says "True."</li></ol>

<div class="moreinformation_section">

Steps to Reproduce Behavior
<ol> Open the sample database Northwind.mdb.</li> Create a new form not based on any table or query and add a command button.</li>  Set the OnClick property of the command button to the following event procedure: Sub Command0_Click MsgBox Application.Modules.Count End Sub </li> Save the form.</li> In the Visual Basic Editor, close the module associated with the form. At this point, no modules are open in the Visual Basic Editor.</li> From the list of projects, open the Startup and Utility Functions modules.</li> Close the Visual Basic Editor and quit Microsoft Access.</li> Open the sample database Northwind.mdb.</li> 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."</li></ol>

Additional query words: prb

Keywords: kbprb KB201298

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.