ACC: Cannot Perform OpenTable Method on Linked/Attached Table

ID: Q138769


The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97


SYMPTOMS

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

If you try to open a recordset on a linked (attached) table by using the dbOpenTable constant (or DB_OPEN_TABLE in version 2.0), you may receive the following error message.

In Microsoft Access 7.0 and 97:

Run-time error '3219':
Invalid Operation.
In Microsoft Access 2.0:
Invalid Operation
In Microsoft Access 1.x:
Can't perform operation; it is illegal.
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.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.


RESOLUTION

In Microsoft Access 2.0, 7.0, and 97:

In Microsoft Access 2.0, 7.0, and 97, a linked table must be opened as the Recordset object. The following code example assumes that you are linked to the Customers table in the sample database Northwind.mdb, which resides in the same folder as the database containing this code. The code opens the Northwind.mdb file, which actually contains the Customers table. The code then creates a recordset based on the Customers table.

Microsoft Access 7.0 and 97:


   Public Function testLink()
 
      Dim myDb As DATABASE, rstCustomers As Recordset
      ' Open the Northwind.mdb database.
      Set myDb = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
      ' Create the recordset.
      Set rstCustomers = myDb.OpenRecordset("Customers", dbOpenDynaset)

   End Function 
Microsoft Access 2.0:

   Public Function testLink()
 
      Dim myDb As DATABASE, rstCustomers As Recordset
      ' Open the Northwind.mdb database.
      Set myDb = DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
      ' Create the recordset.
      Set rstCustomers = myDb.OpenRecordset("Customers", DB_OPEN_DYNASET)
 
   End Function 
In Microsoft Access 1.x:

In Microsoft Access 1.x, an attached table must be opened as the Dynaset object as shown in the following example:

   DIM MyDB as Database
   DIM MyDynaset as Dynaset
   Set MyDB = OpenDatabase("NWIND.MDB")
   Set MyDynaset = MyDB.CreateDynaset("Customers") 


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new, blank database in the same folder as the sample database Northwind.mdb (or NWIND.MDB in versions 1.x and 2.0).


  2. In Microsoft Access 7.0 and 97, on the File menu, point to Get External Data, and then click Link Tables.

    In Microsoft Access 1.x and 2.0, on the File menu, click Attach Table.


  3. In Microsoft Access 7.0 and 97, in the Link dialog box, click Northwind.mdb, and then click Link.

    In Microsoft Access 1.x and 2.0, in the Attach dialog box, click Microsoft Access, and then click OK. In the Select Microsoft Access Database dialog box, click NWIND.MDB, and then click OK.


  4. In Microsoft Access 7.0 and 97, in the Link Tables dialog box, click the Customers table, and then click OK.

    In Microsoft Access 1.x and 2.0, in the Attach Tables dialog box, click Customers, and then click Attach. When prompted that the table is successfully attached, click OK, and then click Close.


  5. Create a module and type the following line in the Declarations section if it is not already there:
    Option Explicit


  6. Type the following procedure:
    
          Function Test()
          Dim db as Database
          Dim mySet as Recordset
             ' In versions 1.x and 2.0, dimension mySet as table.
             ' Dim mySet as table.
          Set db = CurrentDB()
             ' Create the recordset based on the Customers table.
          Set mySet = db.OpenRecordset("Customers", dbOpenTable)
             ' In version 2.0, use the following line to set mySet
             ' Set mySet = db.OpenRecordset("Customers",db_Open_Table).
             ' In version 1.x, use the following line to set mySet.
             ' Set mySet = db.OpenTable("Customers")
          End function 


  7. To test this function, type the following line in the Debug window (or Immediate window in versions 1.x and 2.0), and then press ENTER:
    ? Test()
    Note that you receive the error message described in the "Symptoms" section.



REFERENCES

For more information about the OpenRecordset Method, search the Help Index for "OpenRecordset."

For more information about how to use the Seek method with linked tables, please see the following article in the Microsoft Knowledge Base:

Q131829 ACC: How to Use the Seek Method on Linked Tables

Additional query words:

Keywords : kberrmsg kbprg PgmObj
Version : WINDOWS:1.0,1.1,2.0,7.0,97
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: October 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.