473,782 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex query problem

Hi

I have a form with a number of multi-select lists and drop downs that user
can select to define a search criteria. The result then needs to be shown in
another list on the same form. Normally I would use a number of query
working in series (i.e. one query is source to the other and so on) with
initial queries using more exact criteria that works out fast and reduces
the number of records that following less exact queries need to search
through (speed is an issue).

The problem is that some query stages may not be required if user has not
selected anything from relevant dropdown/list. In this case how can I
achieve the flexibility of skipping certain query stages when needed? Should
I do everything in code to achieve the flexibility? In which case how can
one query be used as a source to another?

Thanks

Regards
Jul 30 '06 #1
2 1227
you have to do it in code. you could define a string to hold the bits
of your query and then evaluate the pieces, adding criteria to your
query the user chooses values. if you're using a multi-select listbox
for query criteria, you don't have any choice, because .ItemsSelected
is a collection, and you'd have to iterate through it to get the
individual values anyway.

Jul 30 '06 #2
Basically, you want to use default values. In Access, a default value
would be a wildcard like *. You could write a sql string something like
this:

Dim strSql As String, strParam1 As String, strParam2 As String

strParam1 = "'*'"
strParam2 = "*"

strSql = "Select * From tbl1 Where fld1 Like " & strParam1 _
& " And fld2 Like '" & strParam2 & "'"

for fld1 I will set the datatype as numeric, fld2 is text. Datatypes of
the Text type require single quote delimeters, but Numeric datatypes
don't require single quote delimeters. However, the wildcard * does
require single quote delimeters if used by text or numeric flds. In
fld2 I hardcode the single quotes into the sql string. But for fld1 I
will place the single quotes inside the strParam1 var.

Since VBA allows late binding, you can replace the value of strParam1
with a numeric value if needed. The default value is '*' for strParam1,
for strParam2 it is * (no single quotes since the single quotes are
hardcoded in the sql string already).

So if you have 5 listboxes, you would have strParam1...str Param5.
Depending on the datatypes (Dates would also be numeric) you assign the
default values. If a user picks a value from any of the listboxes, you
assign that value to the corresponding strParam.

HTH
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 31 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
7890
by: | last post by:
I am trying to run the following agregate function in a parameterized query on Access2000: Min(.*sqr(./.)/) The query saved OK, but an attempt to run it results in the message: The expression is typed incorrectly or it is too complex to be evaluated If the sintax correct? Perhaps it is, otherwise it would not save. What can be done about it?
4
8976
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
2
6078
by: Mikel | last post by:
I am trying to get around the problem "The expression you have entered is too complex" for a select query. (The example below is not the expression that is giving me headaches.) So I am thinking that I just need to do the parsing and calculating in an event procedure for an "On Click" event. My question is: If I have a query field in access97 that parses date (in format
4
2023
by: ED | last post by:
I am attempting to to write a query that has a numerous nested IIf statements. The problem that I am having is that it is to long of a query to be built in design mode and when I build it in sql mode after a certain point it give me the error message that the expression is to complex. Below is the sql code that I am using (this works so far, anything added to the code will give me the to complex error message.) SELECT .WONUM, .,...
0
2215
by: schan | last post by:
Hi there, I was wondering if someone could shed some light on a problem I have no idea on how to fix. I created an Excel Add-In that uses an ADO connection to an Access database on a file server, which in turn has its tables linked to an Oracle back-end. I'm pretty sure I can take out Access as the middleman by just querying against the Oracle database, but that's not my question.
1
2670
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-
1
2822
by: Randy Volkart | last post by:
I'm trying to fix a glitch in a complex access database, and have a fairly complex problem... unless there's some obscure easy fix I don't know being fairly new with Access. Basically, the area I'm trying to fix includes a form which takes entered data, concatenates it into a VB string to form an SQL query, then launches a report with information from the query. Several tables are linked in the query, but the key ones for this problem...
19
3646
by: kawaks40 | last post by:
Hi everyone :) I just recently started using access/sql. and right away I ran into this problem "SQL expression too complex" I google'd a lot on what it means, and the only workaround I've seen sofar, is to just rewrite my code/query. Situation: I am sorting forms into the way they are used (print,storage,readonly,etc...).
3
15930
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is there any parameter that controls how long DB2 allows a statement to compile for.
0
2455
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
9641
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...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
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
7494
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
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3
2875
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.