473,394 Members | 1,755 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,394 software developers and data experts.

AND Query, 5 combo's

I am trying to setup a search facility, such that anything selected in any
of 5 comboboxes is used as criteria unless null or "". I only want to get
back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get
anybody who has either of these colours in table 3. But I can't get it so
that it returns UserID's from only the people who have all colours in the
search.

Can anyone point me in the right direction? Haved searched, read FAQ's
etc - even helping with keywords to continue searching would be appreciated
(is there a name for this type of search?)

Thanks in advance...
Nov 12 '05 #1
5 1993
DFS
1) Create a crosstab query to give you an alternate view of the data in
Table 3

TRANSFORM First(T2.ColorName) AS Colors
SELECT T1.UserID, T1.UserName
FROM T2 INNER JOIN (T1 INNER JOIN T3 ON T1.UserID = T3.UserID) ON T2.ColorID
= T3.ColorID
GROUP BY T1.UserID, T1.UserName
PIVOT T2.Colorid;

Call this query Q_XTAB

Note: this query will show the UserID and Name as the Row Headings, the
ColorIDs as the Column Headings, and the ColorName as the data
2) Bind your comboBoxes to the ColorID and hide it (if you want to - set
width to 0"). If you don't want to put the ColorID in the comboBoxes,
you'll need to change the query to show the ColorName as the ColumnHeadings.
3) Build a dynamic query that processes each comboBox and executes against
Q_XTAB

Public Sub btnSearchBoxes_Click()

'CONFIRM AT LEAST ONE COMBO BOX IS SELECTED
if isnull(me.combo1) and isnull(me.combo2) and isnull(me.combo3) and
isnull(me.combo4) and isnull(me.combo5) then
msgbox "Choose at least one color"
exit sub
endif

'BUILD THE DYNAMIC QUERY
dim cSQL as string
cSQL = SELECT UserID, UserName
cSQL = cSQL & "FROM Q_XTAB "
cSQL = cSQL & "WHERE UserID IS NOT NULL AND "
IF not IsNull(me.combo1) then cSQL = cSQL & "AND " & me.combo1 & " IS NOT
NULL "
IF not IsNull(me.combo2) then cSQL = cSQL & "AND " & me.combo2 & " IS NOT
NULL "
IF not IsNull(me.combo3) then cSQL = cSQL & "AND " & me.combo3 & " IS NOT
NULL "
IF not IsNull(me.combo4) then cSQL = cSQL & "AND " & me.combo4 & " IS NOT
NULL "
IF not IsNull(me.combo5) then cSQL = cSQL & "AND " & me.combo5 & " IS NOT
NULL "

End Sub
That should do it.


"T_2k" <ma*****@tmjones.com> wrote in message
news:bq**********@hercules.btinternet.com...
I am trying to setup a search facility, such that anything selected in any
of 5 comboboxes is used as criteria unless null or "". I only want to get
back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get
anybody who has either of these colours in table 3. But I can't get it so
that it returns UserID's from only the people who have all colours in the
search.

Can anyone point me in the right direction? Haved searched, read FAQ's
etc - even helping with keywords to continue searching would be appreciated (is there a name for this type of search?)

Thanks in advance...

Nov 12 '05 #2
One approach would be:

SELECT User.UserID, User.Name, User.LName
FROM User
WHERE User.UserID IN
(SELECT UserID
FROM UserColour
GROUP BY UserID
HAVING Count(UserID) = 5)

(Replace 5 with however many colours there are in the Colour table)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"T_2k" <ma*****@tmjones.com> wrote in message
news:bq**********@hercules.btinternet.com...
I am trying to setup a search facility, such that anything selected in any
of 5 comboboxes is used as criteria unless null or "". I only want to get
back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get
anybody who has either of these colours in table 3. But I can't get it so
that it returns UserID's from only the people who have all colours in the
search.

Can anyone point me in the right direction? Haved searched, read FAQ's
etc - even helping with keywords to continue searching would be appreciated (is there a name for this type of search?)

Thanks in advance...

Nov 12 '05 #3
DFS
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message
news:mu********************@news04.bloor.is.net.ca ble.rogers.com...
One approach would be:

SELECT User.UserID, User.Name, User.LName
FROM User
WHERE User.UserID IN
(SELECT UserID
FROM UserColour
GROUP BY UserID
HAVING Count(UserID) = 5)

(Replace 5 with however many colours there are in the Colour table)
That wouldn't work. He doesn't want to see the Users having all Colors, he
wants to see the Users having at least the Colors he selects.


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)

"T_2k" <ma*****@tmjones.com> wrote in message
news:bq**********@hercules.btinternet.com...
I am trying to setup a search facility, such that anything selected in any of 5 comboboxes is used as criteria unless null or "". I only want to get back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get anybody who has either of these colours in table 3. But I can't get it so that it returns UserID's from only the people who have all colours in the search.

Can anyone point me in the right direction? Haved searched, read FAQ's
etc - even helping with keywords to continue searching would be

appreciated
(is there a name for this type of search?)

Thanks in advance...


Nov 12 '05 #4
DFS
I just realized something: in case your data in Table3 doesn't have at least
one entry for each color, the xtab query might cause an error if you search
for a color not in the data. You need to list out the ColorIDs in the
Crosstab query. Change the last line to:

PIVOT T2.ColorID in (1,2,3,4,5...)

Note: 1,2,3,4,5... are all the ColorIDs. When you add Colors to Table2,
you'll also need to manually update this xtab query.


"DFS" <no******@nospam.com> wrote in message
news:vs************@corp.supernews.com...
1) Create a crosstab query to give you an alternate view of the data in
Table 3

TRANSFORM First(T2.ColorName) AS Colors
SELECT T1.UserID, T1.UserName
FROM T2 INNER JOIN (T1 INNER JOIN T3 ON T1.UserID = T3.UserID) ON T2.ColorID = T3.ColorID
GROUP BY T1.UserID, T1.UserName
PIVOT T2.Colorid;

Call this query Q_XTAB

Note: this query will show the UserID and Name as the Row Headings, the
ColorIDs as the Column Headings, and the ColorName as the data
2) Bind your comboBoxes to the ColorID and hide it (if you want to - set
width to 0"). If you don't want to put the ColorID in the comboBoxes,
you'll need to change the query to show the ColorName as the ColumnHeadings.

3) Build a dynamic query that processes each comboBox and executes against
Q_XTAB

Public Sub btnSearchBoxes_Click()

'CONFIRM AT LEAST ONE COMBO BOX IS SELECTED
if isnull(me.combo1) and isnull(me.combo2) and isnull(me.combo3) and
isnull(me.combo4) and isnull(me.combo5) then
msgbox "Choose at least one color"
exit sub
endif

'BUILD THE DYNAMIC QUERY
dim cSQL as string
cSQL = SELECT UserID, UserName
cSQL = cSQL & "FROM Q_XTAB "
cSQL = cSQL & "WHERE UserID IS NOT NULL AND "
IF not IsNull(me.combo1) then cSQL = cSQL & "AND " & me.combo1 & " IS NOT
NULL "
IF not IsNull(me.combo2) then cSQL = cSQL & "AND " & me.combo2 & " IS NOT
NULL "
IF not IsNull(me.combo3) then cSQL = cSQL & "AND " & me.combo3 & " IS NOT
NULL "
IF not IsNull(me.combo4) then cSQL = cSQL & "AND " & me.combo4 & " IS NOT
NULL "
IF not IsNull(me.combo5) then cSQL = cSQL & "AND " & me.combo5 & " IS NOT
NULL "

End Sub
That should do it.


"T_2k" <ma*****@tmjones.com> wrote in message
news:bq**********@hercules.btinternet.com...
I am trying to setup a search facility, such that anything selected in any of 5 comboboxes is used as criteria unless null or "". I only want to get back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get anybody who has either of these colours in table 3. But I can't get it so that it returns UserID's from only the people who have all colours in the search.

Can anyone point me in the right direction? Haved searched, read FAQ's
etc - even helping with keywords to continue searching would be

appreciated
(is there a name for this type of search?)

Thanks in advance...


Nov 12 '05 #5
Many, many thanks DFS (and Doug).

"DFS" <no******@nospam.com> wrote in message
news:vs************@corp.supernews.com...
I just realized something: in case your data in Table3 doesn't have at least one entry for each color, the xtab query might cause an error if you search for a color not in the data. You need to list out the ColorIDs in the
Crosstab query. Change the last line to:

PIVOT T2.ColorID in (1,2,3,4,5...)

Note: 1,2,3,4,5... are all the ColorIDs. When you add Colors to Table2,
you'll also need to manually update this xtab query.


"DFS" <no******@nospam.com> wrote in message
news:vs************@corp.supernews.com...
1) Create a crosstab query to give you an alternate view of the data in
Table 3

TRANSFORM First(T2.ColorName) AS Colors
SELECT T1.UserID, T1.UserName
FROM T2 INNER JOIN (T1 INNER JOIN T3 ON T1.UserID = T3.UserID) ON T2.ColorID
= T3.ColorID
GROUP BY T1.UserID, T1.UserName
PIVOT T2.Colorid;

Call this query Q_XTAB

Note: this query will show the UserID and Name as the Row Headings, the
ColorIDs as the Column Headings, and the ColorName as the data
2) Bind your comboBoxes to the ColorID and hide it (if you want to - set
width to 0"). If you don't want to put the ColorID in the comboBoxes,
you'll need to change the query to show the ColorName as the

ColumnHeadings.


3) Build a dynamic query that processes each comboBox and executes against
Q_XTAB

Public Sub btnSearchBoxes_Click()

'CONFIRM AT LEAST ONE COMBO BOX IS SELECTED
if isnull(me.combo1) and isnull(me.combo2) and isnull(me.combo3) and
isnull(me.combo4) and isnull(me.combo5) then
msgbox "Choose at least one color"
exit sub
endif

'BUILD THE DYNAMIC QUERY
dim cSQL as string
cSQL = SELECT UserID, UserName
cSQL = cSQL & "FROM Q_XTAB "
cSQL = cSQL & "WHERE UserID IS NOT NULL AND "
IF not IsNull(me.combo1) then cSQL = cSQL & "AND " & me.combo1 & " IS NOT NULL "
IF not IsNull(me.combo2) then cSQL = cSQL & "AND " & me.combo2 & " IS NOT NULL "
IF not IsNull(me.combo3) then cSQL = cSQL & "AND " & me.combo3 & " IS NOT NULL "
IF not IsNull(me.combo4) then cSQL = cSQL & "AND " & me.combo4 & " IS NOT NULL "
IF not IsNull(me.combo5) then cSQL = cSQL & "AND " & me.combo5 & " IS NOT NULL "

End Sub
That should do it.


"T_2k" <ma*****@tmjones.com> wrote in message
news:bq**********@hercules.btinternet.com...
I am trying to setup a search facility, such that anything selected in

any of 5 comboboxes is used as criteria unless null or "". I only want to get back results where ALL selections are in a table.

The tables are similar to this

1.
UserID Name LName

2.
ColourID ColourName

3.
UserID
ColourID

I can easily do it with an OR style - so that if I selected Blue Red I get anybody who has either of these colours in table 3. But I can't get it so
that it returns UserID's from only the people who have all colours in the search.

Can anyone point me in the right direction? Haved searched, read

FAQ's etc - even helping with keywords to continue searching would be

appreciated
(is there a name for this type of search?)

Thanks in advance...



Nov 12 '05 #6

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

Similar topics

5
by: LouD | last post by:
How can i include a combo box in the criteria field in a parameter query
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
2
by: MLH | last post by:
I invoked the combo-box wizard today, telling it to use a 4-table union query as a row-source for the combo-box it was assisting me in building. The error I got was without number and stated,...
12
by: Tom | last post by:
Hello, I have a database of employee data in access and I am trying to create a form with combo boxes for criteria (ex. gender, office, position, etc.) that let the user select criteria from...
5
by: deaconj999 | last post by:
Hi, I have nearly finished my database and I would like to add a query that uses a combo box to get the results, not the usual paramater style input. I suppose it would need a form and a query...
1
by: commodityintelligence | last post by:
Greetings, I am merging a series of different tables into one query to export decision-making information. I have some architecture issues I need to ask for help on. I have no programming...
3
by: emily.a.day | last post by:
I have a book database, and I have set up a query to search by subject. As it is now, the searcher has to know the subject and type it into the query. I wonder if there is a way to have a combo...
3
hyperpau
by: hyperpau | last post by:
Hi there guys! I have a Form where there are three comboboxes. This comboboxes are used as references for the parameter of 3 fields in a query. when I hit a command button in my form, it opens...
0
by: Del | last post by:
Hello and thanks for any and all assistance! I have a database that is used by several users on several different machines. The backend database is housed on a file server. Each user has a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.