ACC2: "Invalid Operation" Error Msg. Running QueryDef ExampleLast reviewed: April 2, 1997Article ID: Q124341 |
The information in this article applies to:
SYMPTOMSModerate: Requires basic macro, coding, and interoperability skills. When you run the sample QueryDef code on page 251 of the Microsoft Access version 2.0 "Building Applications" manual, you receive the error message "Invalid operation."
CAUSEThis error occurs because the Append method is used incorrectly with the QueryDefs collection. Although the Append method is a valid method for the QueryDefs collection, it is used incorrectly in the sample code. The CreateQueryDef method creates a new QueryDef object and appends it to the QueryDefs collection if it is supplied with a valid name. If you try to append the QueryDef object again using the Append method, you receive an error message because the QueryDef object has already been appended to the collection.
RESOLUTIONThe sample code on page 251 should read as follows. NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.
Dim MyDB As Database, MyQuery as QueryDef Set MyDB = DBEngine.Workspaces(0).Databases(0) ' Create QueryDef. Set MyQuery = MyDB.CreateQueryDef("All Cust", "SELECT * FROM _ Customers;") ' Set SQL property. MyQuery.SQL = "UPDATE DISTINCTROW Products SET _ Products![Supplier ID] = 2 WHERE Products![Supplier ID] = 1;" MyQuery.Execute ' Invoke query. MyQuery.Close ' Close query. STATUSThis behavior no longer occurs in Microsoft Access version 7.0.
MORE INFORMATIONYou can use the Append method with the QueryDefs collection when the CreateQueryDef method does not assign a name to the QueryDef object, as in the following example:
Dim MyDB As Database, MyQuery As QueryDef Set MyDB = DBEngine.Workspaces(0).Databases(0) ' Create QueryDef object without a name. Set MyQuery = MyDB.CreateQueryDef() MyQuery.Name = "All Cust" MyQuery.SQL = "SELECT * FROM Customers;" MyDB.QueryDefs.Append MyQuery REFERENCESMicrosoft Access "Building Applications," version 2.0, Chapter 11, "Working with Sets of Records," page 251
|
Additional query words: kberrmsg
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |