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!
21 13497
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?)
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. -
SELECT tblRevisionAudit.RevisionNumberLookup,
-
tblRevisionAudit.BagNumberLookup,
-
tblRevisionAudit.RevisionAudit,
-
tblRevisionAudit.fldDate,
-
Format([fldDate],"yyyy") AS [Year],
-
tblRevisionAudit.Sort,
-
tblRevisionAudit.[Initials 1],
-
tblRevisionAudit.[Initials 2],
-
tblRevisionAudit.P1,
-
tblRevisionAudit.E1,
-
tblRevisionAudit.P2,
-
tblRevisionAudit.E2,
-
tblRevisionAudit.[CommentsOnAudit:]
-
-
FROM tblRevisionAudit
-
-
WHERE (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
-
AND ((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
-
AND ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2]))
-
OR (((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
-
AND ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null))
-
OR (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
-
AND ((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null))
-
OR (((tblRevisionAudit.RevisionAudit)=[Forms]![frmRevisionAudit]![cboRevisionAudit])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
-
AND (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null))
-
OR (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
-
AND ((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
-
OR (((tblRevisionAudit.BagNumberLookup)=[Forms]![frmRevisionAudit]![BagNumberLookup])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
-
AND (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
-
OR (((tblRevisionAudit.RevisionNumberLookup)=[Forms]![frmRevisionAudit]![RevisionNumberLookup])
-
AND ((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null)
-
AND (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
-
OR (((Format([fldDate],"yyyy"))=[Forms]![frmRevisionAudit]![cboYear])
-
AND ((tblRevisionAudit.Sort)=[Forms]![frmRevisionAudit]![cboSort])
-
AND ((tblRevisionAudit.[Initials 1])=[Forms]![frmRevisionAudit]![cboInitials1])
-
AND ((tblRevisionAudit.[Initials 2])=[Forms]![frmRevisionAudit]![cboInitials2])
-
AND (([Forms]![frmRevisionAudit]![RevisionNumberLookup]) Is Null)
-
AND (([Forms]![frmRevisionAudit]![BagNumberLookup]) Is Null)
-
AND (([Forms]![frmRevisionAudit]![cboRevisionAudit]) Is Null))
-
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.
Well I would a different approach.
To each of your textboxes on the form, I would add: - Private Sub Filter_tb_Title_AfterUpdate()
-
RefreshDocDisplay
-
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! - Private Sub RefreshDocDisplay()
-
'Writes the Filter string to be used on subform
-
-
'Init variables
-
Dim strFilter As String
-
Dim FilterCount As Integer
-
FilterCount = 0
-
-
If IsNull(Me.Filter_tb_DocID) Then
-
'Noting
-
Else
-
'Set string
-
If FilterCount > 0 Then
-
strFilter = strFilter & " AND "
-
End If
-
strFilter = strFilter & "(([tx_DocID] like '*" & Me.Filter_tb_DocID & "*'))"
-
FilterCount = FilterCount + 1
-
-
End If
-
-
If IsNull(Me.Filter_cmb_Binder) Then
-
'Noting
-
Else
-
'Set string
-
If FilterCount > 0 Then
-
strFilter = strFilter & " AND "
-
End If
-
strFilter = strFilter & "(([ID_Binder]=" & Me.Filter_cmb_Binder & "))"
-
FilterCount = FilterCount + 1
-
-
End If
-
-
If IsNull(Me.Filter_tb_Title) Then
-
'Noting
-
Else
-
'Set string
-
If FilterCount > 0 Then
-
strFilter = strFilter & " AND "
-
End If
-
strFilter = strFilter & "(([tx_Title] like '*" & Me.Filter_tb_Title & "*'))"
-
FilterCount = FilterCount + 1
-
-
End If
-
-
If IsNull(Me.Filter_tb_Version) Then
-
'Noting
-
Else
-
'Set string
-
If FilterCount > 0 Then
-
strFilter = strFilter & " AND "
-
End If
-
strFilter = strFilter & "(([tx_Version] like '*" & Me.Filter_tb_Version & "*'))"
-
FilterCount = FilterCount + 1
-
-
End If
-
-
-
If FilterCount > 0 Then
-
'One or more filter criterea set
-
Debug.Print strFilter
-
Me.subFrm_ShowDocsFiltered.Form.Filter = "(" & strFilter & ")"
-
-
Me.subFrm_ShowDocsFiltered.Form.FilterOn = True
-
Else
-
Me.subFrm_ShowDocsFiltered.Form.FilterOn = False
-
-
-
End If
-
-
End Sub
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).
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!
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.
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. :)
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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
|
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
|
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"
|
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,
| |
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...
|
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
|
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-
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |