Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: "Method or Data Member Not Found" Error Message


View products that this article applies to.

Symptoms

When you compile a module that has a procedure which tries to call another procedure that is in a class module in another database, you may receive the following error message:
Method or Data Member not Found.

↑ Back to the top


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.

↑ Back to the top


Resolution

Use one of the following two methods to work around this behavior.

Method 1

Store the procedure in a standard module rather than in a class module. This makes the procedure directly accessible from other databases but requires 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 calls the procedure from the class module. Then, you call this function from a standard module of another database. This allows you to leave your class module procedures as they are, but requires that you write a standard procedure for each class module procedure that you want to run.

↑ Back to the top


More information

Although you cannot directly call a procedure defined in a class module of another database from procedures outside of that database, you may notice that you can call them from the Immediate window. The reason for this is that Visual Basic for Applications relaxes privacy rules and scope restrictions in the Immediate window to aid in debugging procedures.

Steps to Reproduce Behavior

  1. Start Microsoft Access and create a new database called Class.mdb.
  2. Open a new blank form in Design view.
  3. On the View menu, click Code.
  4. Type the following function:
    Option Compare Database
    Option Explicit
    
    Public Function ClassModuleTest()
      MsgBox "Hello"
    End Function
    					
  5. Save the form as ClassForm, and then close it.
  6. Close the database.
  7. Open the sample database Northwind.mdb.
  8. Open a new global module in Design view.
  9. On the Tools menu of the Visual Basic Editor, click References.
  10. In the References dialog box, click Browse.
  11. In the Add References dialog box, click Microsoft Access Databases (*.mdb) in the Files of type list.
  12. Click Class.mdb, and then click Open to add the database as a reference.
  13. Click OK to close the References dialog box.
  14. On the View menu, click Immediate Window.
  15. Type the following line in the Immediate window, and then press ENTER:
    ? [Class].Form_ClassForm.ClassModuleTest()
    Note that the procedure runs and the "Hello" message box is displayed.
  16. Type the following function:
    Public Function RunClassProc()
    Dim x
    x = [Class].Form_ClassForm.ClassModuleTest()
    End Function
    					
  17. Try to compile the procedure by clicking Compile Northwind on the Run menu. Note that you receive the following error message:
    Compile Error:

    Method or Data Member not Found.

↑ Back to the top


References

For more information about creating references, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type references property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about class modules, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type class modules in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB198650, kbprb, kbprogramming, kberrmsg

↑ Back to the top

Article Info
Article ID : 198650
Revision : 2
Created on : 7/16/2004
Published on : 7/16/2004
Exists online : False
Views : 272