473,796 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I workaround query being too complex

wordbrew
29 New Member
I thought I was done with my database, everything was working great, but after going into the query that my subform is based on and simply changing a field from ascending to descending, then closing that and trying to open my form, I got the "query is too complex" error and then everthing went south. Access closed itself and the file was unrecoverable. Luckily I had saved this file with 2 other backups! I tested again. Everything works fine in the form if I don't touch anything else, but just by opening and closing the query (without trying to change anything), the same "too complex scenario" happens again.

The query has 13 fields, with 8 of them having had criteria similar to this typed in them:

[Forms]![frmRevisionAudi t]![cboRevisionAudi t] Or [Forms]![frmRevisionAudi t]![cboRevisionAudi t] Is Null.

One of the fields had the criteria [Forms]![frmRevisionAudi t]![cboYear] Or [Forms]![frmRevisionAudi t]![cboYear] = "All".

Once I close this, if I open it back up, the query has restructured itself by filling the rows with every possible combination of criteria to return my results to the main form based on 7 combo box filters.

Is there a way for me to word this or structure this differently or use different phrasing to get my desired results without bloating my query sql a mile long?

I really appreciate any help or suggestions. I'm still an amateur at Access and am fully willing to be called a dunderhead if this is a common mistake to avoid. :) I only care about learning, improving, and getting to the final working end result.

Thanks so much!
Mar 12 '10 #1
21 13497
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Try posting your full SQL syntax here. Are you working only internally in Access, or does the access database run of a backend (and if so, what kind?)
Mar 12 '10 #2
wordbrew
29 New Member
Thanks for replying Smiley!

All of this is done in Access alone. Unfortunately, what seems simple when entering into the criteria section of the query design view, bloats into a huge sql statement. I'm going to only post a snippet (which is still big) because posting the entire statement would too cumbersome. Hopefully this will give you the idea.
Expand|Select|Wrap|Line Numbers
  1. SELECT tblRevisionAudit.RevisionNumberLookup,
  2.        tblRevisionAudit.BagNumberLookup,
  3.        tblRevisionAudit.RevisionAudit,
  4.        tblRevisionAudit.fldDate,
  5.        Format([fldDate],"yyyy") AS [Year],
  6.        tblRevisionAudit.Sort,
  7.        tblRevisionAudit.[Initials 1],
  8.        tblRevisionAudit.[Initials 2],
  9.        tblRevisionAudit.P1,
  10.        tblRevisionAudit.E1,
  11.        tblRevisionAudit.P2,
  12.        tblRevisionAudit.E2,
  13.        tblRevisionAudit.[CommentsOnAudit:]
  14.  
  15. FROM   tblRevisionAudit
  16.  
  17. WHERE  (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
  18.   AND  ((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
  19.   AND  ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
  20.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  21.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  22.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  23.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2]))
  24.    OR  (((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
  25.   AND  ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
  26.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  27.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  28.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  29.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  30.   AND  (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null))
  31.    OR  (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
  32.   AND  ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
  33.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  34.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  35.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  36.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  37.   AND  (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null))
  38.    OR  (((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
  39.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  40.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  41.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  42.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  43.   AND  (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
  44.   AND  (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null))
  45.    OR  (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
  46.   AND  ((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
  47.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  48.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  49.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  50.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  51.   AND  (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
  52.    OR  (((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
  53.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  54.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  55.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  56.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  57.   AND  (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
  58.   AND  (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
  59.    OR  (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
  60.   AND  ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  61.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  62.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  63.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  64.   AND  (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null)
  65.   AND  (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
  66.    OR  (((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
  67.   AND  ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
  68.   AND  ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
  69.   AND  ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
  70.   AND  (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
  71.   AND  (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null)
  72.   AND  (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
  73.    OR    .....etc.
The sql statement runs on for about 5 or 6 times this length. I just wish I new how to restate everything so this crazy cascade doesn't happen. Like I said, right now in the query design view, under, say the field RevisionAudit, that is pulling from tblRevisionAudi t, in the criteria section I am putting [Forms]![frmRevisionAudi t]![cboRevisionAudi t] Or [Forms]![frmRevisionAudi t]![cboRevisionAudi t] Is Null, so that of course when my combo box on my main form is empty, then the subform will display all records for that combo box. But since I have 8 other fields I'm doing something similar with, when I close the query, Access is creating a slew of rows to deal with every situation.

Ultimately I just want my 7 combo boxes on my main form to be able to filter my subform in a bunch of combinations, including returning all results for a blank combo box.

I just hope there's a simple solution that I'm overlooking. The database is working fine if once I close the query I don't touch it again. But I do NOT want a database tetering on the edge of disaster with one false move lol.
Mar 12 '10 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Well I would a different approach.
To each of your textboxes on the form, I would add:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Filter_tb_Title_AfterUpdate()
  2.     RefreshDocDisplay
  3. End Sub
Where RefreshDocDispl ay is a procedure on the same form, building and applying a filterstring to the subform.

For each of the textboxes in question, it will go through it, and decide whether or not to add it to the string (for instance it won't add it if textbox/combobox is null). When the build is complete, it will apply the string.

In case your wondering the FilterCount is used to keep track of whether or not to add the " AND " part. I hope this can help you!

Expand|Select|Wrap|Line Numbers
  1. Private Sub RefreshDocDisplay()
  2. 'Writes the Filter string to be used on subform
  3.  
  4. 'Init variables
  5.     Dim strFilter As String
  6.     Dim FilterCount As Integer
  7.     FilterCount = 0
  8.  
  9. If IsNull(Me.Filter_tb_DocID) Then
  10.     'Noting
  11.     Else
  12.     'Set string
  13.     If FilterCount > 0 Then
  14.         strFilter = strFilter & " AND "
  15.     End If
  16.     strFilter = strFilter & "(([tx_DocID] like '*" & Me.Filter_tb_DocID & "*'))"
  17.     FilterCount = FilterCount + 1
  18.  
  19. End If
  20.  
  21. If IsNull(Me.Filter_cmb_Binder) Then
  22.     'Noting
  23.     Else
  24.     'Set string
  25.     If FilterCount > 0 Then
  26.         strFilter = strFilter & " AND "
  27.     End If
  28.     strFilter = strFilter & "(([ID_Binder]=" & Me.Filter_cmb_Binder & "))"
  29.     FilterCount = FilterCount + 1
  30.  
  31. End If
  32.  
  33. If IsNull(Me.Filter_tb_Title) Then
  34.     'Noting
  35.     Else
  36.     'Set string
  37.     If FilterCount > 0 Then
  38.         strFilter = strFilter & " AND "
  39.     End If
  40.     strFilter = strFilter & "(([tx_Title] like '*" & Me.Filter_tb_Title & "*'))"
  41.     FilterCount = FilterCount + 1
  42.  
  43. End If
  44.  
  45. If IsNull(Me.Filter_tb_Version) Then
  46.     'Noting
  47.     Else
  48.     'Set string
  49.     If FilterCount > 0 Then
  50.         strFilter = strFilter & " AND "
  51.     End If
  52.     strFilter = strFilter & "(([tx_Version] like '*" & Me.Filter_tb_Version & "*'))"
  53.     FilterCount = FilterCount + 1
  54.  
  55. End If
  56.  
  57.  
  58. If FilterCount > 0 Then
  59.     'One or more filter criterea set
  60.     Debug.Print strFilter
  61.     Me.subFrm_ShowDocsFiltered.Form.Filter = "(" & strFilter & ")"
  62.  
  63.     Me.subFrm_ShowDocsFiltered.Form.FilterOn = True
  64.     Else
  65.     Me.subFrm_ShowDocsFiltered.Form.FilterOn = False
  66.  
  67.  
  68. End If
  69.  
  70. End Sub
Mar 12 '10 #4
NeoPa
32,579 Recognized Expert Moderator MVP
Definitely the way to go :)

I generally add the " AND " bit at the front in all circumstances, then simply use Mid(strFilter, 6) just before applying it (wherever that may be in the code).
Mar 13 '10 #5
wordbrew
29 New Member
Thanks so much Smiley, I'm going to try and dig into this today. I'm glad it's a VBA workaround cause I really need to keep honing my skills on it (which are minimal). To make sure, I keep my subform still based on the query I created, and I still put the criteria in the fields in the query design view, such as Forms!frmRevisi onAudit!cboRevi sionAudit (so that they still take their direction from the combo box on the main form) but I don't worry about all the other Null business. I let the VBA code handle all of that?

Thank again. I'll get crackin. And thanks NeoPa for chippin in too!
Mar 13 '10 #6
NeoPa
32,579 Recognized Expert Moderator MVP
You're welcome.

I'm not sure I understand your clarification question too well, but as a general rule, the design of the query itself would still contain any references that are generally required (not dependent), whereas the code would be used for adding items that depend on things.

IE. If you had a table of animals, but you had a report that showed all elephants between the largest and smallest values entered on a form, you would design a query, based on the table, which had designed selection criteria of Type='Elephant', but the form's code would build and add a filter of something like Between Forms!YourForm. Smallest And Forms!YourForm. Largest, possibly adding it only if both entries had values entered.
Mar 13 '10 #7
wordbrew
29 New Member
I've put in the VBA code suggested by TheSmileyOne, but I think I'm just so new to the concept of filtering via VBA that I'm just fudging up somewhere. I'm including the database here, with the code i've put in. If someone could take a look and tell me where I'm going utterly wrong I would appreciate it. Hopefully I was getting close and just missing a key concept. But if I was way off base, then please giggle away. :)
Attached Files
File Type: zip Flight Manuals TEST.zip (243.0 KB, 157 views)
Mar 13 '10 #8
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Alot of place you had written Me.Filter.Revis ionLookup, the .Filter should not be there.

I fixed it for the first combobox, the revision lookup, then you can work for there.

Note that I switched the syntax from using a Like "*"..... to =, since your using a combobox with ID fields.

I removed all the criteria from the query of the subform, the only criteria you should use there, are ones NOT related to the form.

You also (as far as i know) do not need to requery after setting the filterstring, so I removed that for the first combobox bit of code as well.

Have a look, see if you can make it work.
Attached Files
File Type: zip Flight Manuals TEST.zip (253.3 KB, 145 views)
Mar 13 '10 #9
wordbrew
29 New Member
Alright, I've tried replacing and configuring the other VBA from what i could divine from your changes. I even went back and changed the names of the other boxes so I could make things look consistent. But I'm just not seeing something.

I don't know if it's because two of my combo's are based on value lists cmb_RevisionAud it, and cmb_Sort and/or my cmb_Year needs to sort just the year in the fldDate field in the query, which it was doing before in the query, but now the year format probably needs to be put in the VBA filter.

I really appreciate everything I've been helped with, and I don't expect to have it tinkered with and handed back to me working lol, if I could just get a few tips on where I'm going wrong that would be wonderful. You've already been awesome expending valuable time on my problem.
Attached Files
File Type: zip Flight Manuals TEST.zip (241.9 KB, 116 views)
Mar 13 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3055
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going on? I have tested this extensively and can say for certain that installing this hot fix is what has caused the performance problem. I just don't know why or how to fix it. Brian Oster
3
2355
by: Andrew Mayo | last post by:
There is something very strange going on here. Tested with ADO 2.7 and MSDE/2000. At first, things look quite sensible. You have a simple SQL query, let's say select * from mytab where col1 = 1234 Now, let's write a simple VB program to do this query back to an MSDE/2000 database on our local machine. Effectively, we'll
4
8977
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to various forums where I am forced to sign up before I can read any answers. Interesting note here is that the guy in the office next
8
5068
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can have a query that will pull a single field from all the tables. In other words i should have 44 fields. when i try to do that same, i get an error message saying "Query is too complex"
2
1837
by: Ben de Vette | last post by:
Hi, I'm using the querybuilder when updating a record in a table (Access). However, I get a "Query is too complex" message. The Primary key is autonumbered. Why is it making such a complex update query string in stead of using the primary key? Thanks in advance,
9
2905
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user wants to be able to check off anywhere between 1 and all 10 fields in a form and have it return a select query with just the fields that were checked off. There are multiple users, so not all users will be checking off the same fields. Some...
10
2112
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social Security # or on Last Name. I've created two different tables with the following fields in each table: ClientInfo Client# (primary key) First Name Middle Name Last Name
1
2671
by: arun | last post by:
Query is too complex -------------------------------------------------------------------------------- Hi, I was trying to solve this problem since last two days but couldn't find any solution. I wanted to execute a query which is retrieving the records from table1 by checking the condition for a long long string . I'm using where clause and checking the condition as-
8
6729
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this cover letter for each applicant, there has to be attached a two page document. How in the world can...
0
2456
crystal2005
by: crystal2005 | last post by:
Hi, I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following 1. The wine name, grape variety, year, winery, and region 2. The minimum cost of wine in the inventory 3. The number of bottles available at the minimum price 4. The total number of bottles available at any price 5. The total number of unique...
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7548
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.