Microsoft KB Archive/138769

= ACC: Cannot Perform OpenTable Method on Linked/Attached Table =

Article ID: 138769

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q138769



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



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



Steps to Reproduce Behavior
 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). 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. 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. 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. Create a module and type the following line in the Declarations section if it is not already there:

Option Explicit

</li>  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 </li> 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.</li></ol>

<div class="references_section">