Hi there. I've been using DAO in a VB6 program (everything working well) but I'm changing things to ADO so I have an easier time migrating to SQL and eventually out of VB6 entirely.
I'm a total ADO noob so sorry if I've made some really basic error here.
I ran into the weirdest problem. If I understand this properly, it seems ADO is limited to updating records with only 40 fields or less. My database has about 60 fields. I know... bad design. But too hard to change that right now if I don't need to.
I read on the Microsoft site I should include this: myData.Properties("Update Criteria").value = adCriteriaKey but I have to say I didn't really understand the article and may not have done things properly but it made no difference.
Every time I try to update any record in my database I get a "Query is too complex" error.
Re: More than 40 fields in ADO Query is too Complex
Originally Posted by DataMiser
what is in mstrSQL ?
The place where you have constring$ should be a connection object
Thanks for your reply. Yes, well aware. The connection string is working fine. I can read the database fine and update tables with fewer than 40 fields. This is a well known issue for ADO databases with more than 40 fields but I cant find a work-around. Or rather I cant make it work. I didn't include my connection string it for brevity.
Re: More than 40 fields in ADO Query is too Complex
google found this
SUMMARY
The following error occurs when using RDO or ADO to update data in an Access (Jet) database:
Query is too complex
Due to a limitation of the Jet database engine, this error can occur if the recordset to be updated contains more than 40 fields.
Using the Jet 3.51 engine, the error occurs if the recordset to be updated contains more than 50 fields. With the Jet 4.0 engine and later, the error occurs if the recordset to be updated contains more than 99 fields.
Using the Jet 4.0 engine and later, you may also see the errors:
Expression too complex
-or-
Too many defined fields
This article describes the problem scenario, the Jet limitation, and several workarounds.
There are several ways to avoid this behavior:
For new applications, use DAO when working with Access databases. DAO was designed for this purpose, and will not issue a SQL query to perform the update. Note that RDO and especially ADO were designed to operate efficiently with many other types of databases and are recommended for applications that will interact with various servers or that will be upsized in the future to use Microsoft SQL Server, for example.
When opening the recordset to be updated (such as the RDO OpenResultset or ADO OpenRecordset methods), select specific, and 40 or fewer fields.
Use a server-side cursor:
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Re: More than 40 fields in ADO Query is too Complex
Yes, thanks for that reply. I read that one. I'm trying to get rid of DAO but I guess I may have to keep it around for updating this one large table. Or redesign the database.
I was looking at this part from that article...
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Properties("Update Criteria").Value = adCriteriaKey
rs.Open ...
...
Re: More than 40 fields in ADO Query is too Complex
according to the article, if you use jet 4.0 you can have up to 99 fields
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case. Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Re: More than 40 fields in ADO Query is too Complex
Originally Posted by gibra
ConString$ is totally wrong
Thanks for the help with the connection string. I'm sure it was wrong and it's nice to have it done properly. Sadly the end result is the same.
Once the database is open, any attempt to use the .update function on the record set generates a "Query too complex" error because I have too many fields.
Editing other tables in the same database works fine so I know things are open properly.
This seems to be just a fundamental limit of ADO.
This program is designed to emulate an old paper form of some type. There are 10 rows. Each row has 9 fields plus a few extras up top for name and date, etc. I thought it was about 60 fields but the entire record has almost 100 fields. Maybe even more. Uggg. It would be more sensible to break the record up into smaller segments and link them together. But that's a lot of coding. *sigh* Time to get typing.
Last edited by Darkbob; Mar 25th, 2016 at 01:19 PM.
Re: More than 40 fields in ADO Query is too Complex
Thanks for the tips on the connection string. Very helpful but not for this particular issue.
From what I can see a client side cursor does allow dynamic recordsets plus it allows lots of other things I'm using (and shouldn't be) like Bookmarks.
I know my code above doesn't show it but previous posts have helped fix that up. The record set is open, the cursor is set right, the locks are set right. Honest.
There may be minor tweaks to the connection string to make is nicer looking but that's seriously not the problem. I promise. It's the number of fields. Just way too many of them.
Now just trying to figure out how to remove fields from an ADO database but that's another thread.
Last edited by Darkbob; Mar 25th, 2016 at 02:59 PM.
Re: More than 40 fields in ADO Query is too Complex
Rather than solve this problem, there may be a way to avoid it ?
I have not used the update method of a rs for years.
I use ACTION Updates instead
I never maintain a connection
I get rs and load into grid (or whatever) close rs and disconnect
When user modifies a record, I do an ACTION Update (no rs involved)
Something like this -
Re: More than 40 fields in ADO Query is too Complex
DarkBob,
I have been composing an example project that demonstrates ACTION Inserts, Modifies and Deletes.
But I am extremely hesitant to attach it, as it will invite more insensitive/hurtful abuse.
Can you ask the offender to back off
Re: More than 40 fields in ADO Query is too Complex
Originally Posted by Bobbles
DarkBob,
I have been composing an example project that demonstrates ACTION Inserts, Modifies and Deletes.
But I am extremely hesitant to attach it, as it will invite more insensitive/hurtful abuse.
Can you ask the offender to back off
OK you haters - yes I'm looking at you! Back off and let Bobbles post his project!
Re: More than 40 fields in ADO Query is too Complex
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.
and
4.Ensure that a unique key is used to identify the record to be updated, rather than the default behavior of using every field. A unique key (though not necessarily a primary key) must be defined in the underlying recordset for this technique to work. •To do this in ADO (this will not work in versions prior to ADO 2.0), set the Recordset object's "Update Criteria" property to adCriteriaKey. This will work both for the Update() and UpdateBatch() methods:
---seems logical to me---
if the recordset is created from a select that does not include a key
how is the update to know what row to update in the table ?
---on the other hand---
say you have a table with 39 fields
and a recordset created with only 3 fields,none of wich is a key (or any combination of the 3 is a key)
how is the update to know what row to update in the table ?
could it be that every select,no matter how many fields, always retrieves all the fields ???
but only shows the selected fields ???
do not put off till tomorrow what you can put off forever
Re: More than 40 fields in ADO Query is too Complex
could it be that every select,no matter how many fields, always retrieves all the fields ???
but only shows the selected fields ???
but what if there are duplicate rows in the table ?
not even retrieving all the fields will suffice to know what row to update
but then:
if a table has duplicate rows, it is not a relation
and hence all bets are off when using sql
but i am not staying on the subject...sorry...just had to say it
do not put off till tomorrow what you can put off forever