ACC97: Cannot View Class Module in a Referenced Database Library

Last reviewed: August 29, 1997
Article ID: Q160011
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

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

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

  1. Create a new database called ClassTestRef.mdb.

  2. On the Insert menu, click Class Module.

  3. Save the class module as clsTest.

  4. Select Class in the Object box of the module window. "Initialize" is automatically selected in the Procedure box of the module window.

  5. 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
    
    

  6. Type the following public procedure:

          Public Function CallClass()
    
             MsgBox "clsTest.CallClass method", _
                     vbInformation, "Class Example"
          End Function
    
    

  7. Save and close the clsTest class module.

  8. Create a new standard module by clicking Module on the Insert menu.

  9. Type the following line in the Declarations section:

          Public cls As New clsTest
    

  10. Save the module as modTest and close it.

  11. Close the ClassTestRef.mdb database.

Create the Front-End Database

  1. Create a new database called ClassTestFront.mdb.

  2. Create a new standard module by clicking Module on the Insert menu, and

        then save the module as Module1.
    

  3. On the Tools menu, click References.

  4. In the References dialog box, click Browse.

  5. 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.

  6. Note the new reference to ClassTestRef in the References dialog box, and then click OK.

  7. 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
    
    

  8. 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."
    

  9. Open Module1 in Design view.

  10. On the View menu, click Object Browser.

  11. 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.
    

REFERENCES

For more information about class modules, search the Help Index for "class modules," or ask the Microsoft Access 97 Office Assistant.

For more information about the Object Browser, search the Help Index for "Object Browser," or ask the Microsoft Access 97 Office Assistant.


Additional query words: ClassMod OLE instance
Keywords : kbusage PgmCM MdlLib
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.