Microsoft KB Archive/160011

= ACC97: Cannot View Class Module in a Referenced Database Library =

Article ID: 160011

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q160011



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



SYMPTOMS
When you open the Object Browser in Microsoft Access 97, you cannot view any of the form or report class modules in a referenced database.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to the "Building Applications with Microsoft Access 97" manual.



CAUSE
Microsoft Access 97 corrects an anomaly with class module visibility that exists in Microsoft Access 7.0 by not allowing you to browse or view any form, report, or stand-alone class modules in a referenced database.

Microsoft Access 7.0 allows you to use the Object Browser to browse forms and reports (stand-alone class modules are not supported in version 7.0), and to call their methods and properties. Microsoft Access 97 corrects this behavior by marking all form, report and stand-alone class modules as private.



RESOLUTION
To make a class module visible in the Object Browser, declare a public variable in a standard module in the referenced database that encapsulates the class module.



MORE INFORMATION
Microsoft Access 7.0 and 97 both support calling functions from an external database by creating a Visual Basic for Applications reference. This allows you to use the Object Browser to view functions marked as Public in a referenced database, and call the code from within the current database.

The following example creates a class object in a referenced database to demonstrate how to call functions in a class module of a referenced database, and to illustrate how the reference appears in the Microsoft Access 97 Object Browser.

Create the Reference Database
 Create a new database called ClassTestRef.mdb. On the Insert menu, click Class Module. Save the class module as clsTest. Select Class in the Object box of the module window. "Initialize" is automatically selected in the Procedure box of the module window.  Type the following procedure for the Initialize event: Private Sub Class_Initialize On Local Error GoTo Class_Initialize_Err Dim Msg As String MsgBox "Class Initialized", vbInformation, "Class Example" Class_Initialize_End: Exit Sub Class_Initialize_Err: Msg = "Error #: " & Format$(Err.Number) & vbCrLf Msg = Msg & Err.Description Err.Raise vbObjectError, "clsTest.Initialize (Private)", Msg Resume Class_Initialize_End End Sub </li>  Type the following public procedure: Public Function CallClass MsgBox "clsTest.CallClass method", _ vbInformation, "Class Example" End Function </li> Save and close the clsTest class module.</li> Create a new standard module by clicking Module on the Insert menu.</li>  Type the following line in the Declarations section: Public cls As New clsTest </li> Save the module as modTest and close it.</li> Close the ClassTestRef.mdb database.</li></ol>

Create the Front-End Database
<ol> Create a new database called ClassTestFront.mdb.</li> Create a new standard module by clicking Module on the Insert menu, and then save the module as Module1.</li> On the Tools menu, click References.</li> In the References dialog box, click Browse.</li> In the Add Reference dialog box, select Microsoft Access Databases (*.mdb) in the File name box, and then select the ClassTestRef.mdb file. Click OK.</li> Note the new reference to ClassTestRef in the References dialog box, and then click OK.</li>  Type the following procedure in the open module. This procedure calls the public CallClass function of the clsTest class module in the ClassTestRef database: Public Function TestClass As Boolean cls.CallClass TestClass = True End Function </li> To test this function, type the following line in the Debug window, and then press ENTER.

? TestClass

Note that you receive two message boxes; the first one displays the text "Class Initialized," and the second one displays the text "clsTest.CallClass method."</li> Open Module1 in Design view.</li> On the View menu, click Object Browser.</li> <li>Select ClassTestRef in the Project/Library box. Note that only modTest is visible in the Classes box, and that you can see the public variable cls that it contains; the class module clsTest is not visible in the Object Browser.</li></ol>

<div class="references_section">