HOWTO: Update More Than 40 fields in an Access (Jet) DatabaseID: Q192716
|
A "Query is too complex" error occurs when using RDO or ADO to update data in an Access (Jet) database. Due to a limitation of the Jet database engine, this error can occur if the recordset to be updated contains more than 40 fields. This article describes the problem scenario, the Jet limitation, and several workarounds.
When executing the Update() or BatchUpdate() methods of RDO's rdoResultset
object, or the Update() or UpdateBatch() methods of ADO's Recordset object,
the ODBC error S1000 "Query is too complex" (Visual Basic run-time error
40002) occurs.
This behavior occurs because the default behavior of ADO and RDO is to use
each field in the recordset to determine the record to be updated on the
server. That is, when the update is attempted, a SQL Update query is sent
to the server. Part of this query is a WHERE clause that is used to
identify the record to be updated. An AND clause appears within the WHERE
clause for each field to be used in that identification. Updating a
recordset with more than 40 fields involves a WHERE clause with more than
40 ANDs.
The Jet engine allows only 40 AND clauses within a SQL WHERE or HAVING
clause. The Access ODBC driver returns a "Query is too complex" error when
it encounters such a SQL statement. See the REFERENCES section of this
article for more information.
There are several ways to avoid this behavior:
...
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
rs.Open ...
...
...
Dim eng As RDO.rdoEngine
Dim cn As RDO.rdoConnection
Dim env As RDO.rdoEnvironment
Dim rs As RDO.rdoResultset
Set eng = New rdoEngine
Set env = eng.rdoCreateEnvironment(...)
env.CursorDriver = rdUseServer
Set cn = env.OpenConnection(...)
Set rs = cn.OpenResultset(...)
...
...
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Properties("Update Criteria").Value = adCriteriaKey
rs.Open ...
...
...
Dim eng As RDO.rdoEngine
Dim cn As RDO.rdoConnection
Dim env As RDO.rdoEnvironment
Dim rs As RDO.rdoResultset
Set eng = New rdoEngine
Set env = eng.rdoCreateEnvironment(...)
env.CursorDriver = rdUseClientBatch
Set cn = env.OpenConnection(...)
Set rs = cn.OpenResultset(...)
rs.Edit
...
rs.UpdateCriteria = rdCriteriaKey
rs.Update
...
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q92690 : ACC: Limit on ANDs in SQL Select Statement
Additional query words: kbDSupport kbVBp kbdse kbADO200 kbADO150 kbRDO200 kbVBp500 kbVBp600
Keywords :
Version : WINDOWS:1.5,2.0,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 24, 1999