Microsoft KB Archive/151572

= ACC: Error Message "Method or Data Member Not Found" =

Article ID: 151572

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q151572



SYMPTOMS
Advanced: Requires expert coding, interoperability, and multiuser skills.

When you compile a module in which a procedure is trying to call a procedure that is defined in a class module in another database, you may receive the following error message:

Method or Data Member not Found.



CAUSE
Class modules are private in scope to the Visual Basic project in the database in which they are defined. Therefore, procedures in class modules cannot be referenced in another Visual Basic project.

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 your version of the "Building Applications with Microsoft Access" manual.



RESOLUTION
You can use one of the following two methods to work around this behavior.

Method 1
Store the procedure in a standard module rather than a class module. This would make the procedure directly accessible from other databases but would require that you convert your class module procedures to standard module procedures.

Method 2
Create a function in a standard module in the database where the class module is defined. This function would call the procedure from the class module. Then, you would call this function from a standard module of another database. This allows you to leave your class module procedures as is, but would require that you write a standard procedure for each class module procedure you want to run.



MORE INFORMATION
Although its not possible to directly call a procedure defined in a class module of another database from procedures outside of that database, you may notice that it is possible to call them from the Debug window. This is because Visual Basic for Applications relaxes privacy rules and scope restrictions in the Debug window to aid in debugging Visual Basic procedures.

Steps to Reproduce Behavior
 Start Microsoft Access and create a new database called Class.MDB. Open a new blank form in Design view. Click Code on the View menu to view the form's module.  Create the following function: Option Compare Database Option Explicit

Public Function ClassModuleTest MsgBox "Hello" End Function  Save and close the form as ClassForm. Close the database.</li> Open the sample database Northwind.mdb.</li> Open a new global module in Design view.</li> On the Tools menu, click References.</li> In the References dialog box, click the Browse button to browse for a new reference.</li> In the Add References dialog box, under Files OF Type, select Databases.</li> Select the Class.MDB database, and click OK to add it as a reference.</li> Click OK to close the References dialog box.</li> On the View menu, click Debug Window to open the Debug Window.</li> Type the following line in the Debug window, and then press ENTER.

In Microsoft Access 97:

? [Class].Form_ClassForm.ClassModuleTest

In Microsoft Access 7.0:

? [Class.MDB].Form_ClassForm.ClassModuleTest

Note that the procedure runs and the "Hello" message box is displayed.</li>  Create the following function:

In Microsoft Access 97: Public Function RunClassProc Dim x      x = [Class].Form_ClassForm.ClassModuleTest End Function In Microsoft Access 7.0: Public Function RunClassProc Dim x      x = [Class.MDB].Form_ClassForm.ClassModuleTest End Function </li> Try to compile the procedure by clicking Compile Loaded Modules on the Run menu. Note that you receive the following error message:

Method or Data Member not Found.

</li></ol>

<div class="references_section">