473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 1213
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...strParam5.
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
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...
4
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...
2
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...
4
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...
0
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...
1
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. ...
1
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...
19
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...
3
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...
0
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 ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.