473,503 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex filters...

41 New Member
I have set a database up to record the answers to a set of questions. In order to allow multiple answers to a question I decided to store the results in another table in the following format.

Response ID, Question ID, Answer ID

(There are another few fields but they’re not relevant)

This works fine for storing the responses, it allows me to have as many questions as I need, each with as many answers as I need.

Unfortunately I did not think about how I could report on this information. Obviously finding out the number of people who answered a particular question with a particular answer is easy but my manager has now stated that she wants to cross reference questions.

For example, if one of the questions were “Do you work for company A or B?” (Question ID 1) and the possible answers were Yes and No (answer ID 1 and 2)

This would need cross referencing with another question “Which website/s experienced the problems” (question ID 2) and there are say 10 possible answers (Answer ID 3-13)

I know what I need to do, but I just don’t understand who I would do this in Access.

Basically I need to filter my table for all Question ID 1 where the answer was Answer ID 1. (People who had a problem with the internet). Using this filter I need to make a record of the Response ID’s which had a problem with the internet and use this list to make another filter on a table. (so this new filter would now show the full response for everyone who had answered yes to the first question)

e.g.

Response ID, Question ID, Answer ID

1,1,1
1,2,5
1,2,6
1,2,9
2,1,1
2,2,5
2,2,6
3,1,2
4,1,1
4,2,9
5,1,2

This would be the contents of a table where 5 people had responded.
3 of the respondents have answered Yes to question 1
2 of the respondents have answered No to question 1.

I now need to filter this list for any Question ID 1 where the Answer ID is also 1. (The result of this filter for this example would be:

1,1,1
2,1,1
4,1,1

Obviously this isn’t really helpful as it has filtered out all of the other questions, but what it has done is provided me with a list of the response ID who has answered yes to question 1 (1,2 and 4). In this example there is only 3, but this could potentially be 1000)

So far im fine up to this point. Performing the initial filter is easy - What I need to know now is, is it possible to generate another filter from the contents of the first field in my filter? Then displaying all of the data from those particular respondent ID’s?
(1,2 and 4)

This would be:

1,1,1
1,2,5
1,2,6
1,2,9
2,1,1
2,2,5
2,2,6
4,1,1
4,2,9

Which I could now do another filter on to find out cross referenced answers, such as which particular websites caused the problem.

Now I must explain that this is just an example question, the system is currently designed so it has a full admin section where you can design questions and answer sets, so the question and answers needing cross-referenced could potentially be about anything. It is likely that each question”set” would have many more questions and possible answers.

I know this is quite complicated and i’ve probably not explained it that well but any help to point me in the right direction (or even tell me it’s not possible) would be greatly appreciated.
Jan 21 '08 #1
13 2364
Craggy
41 New Member
Is there a limit to how long a filter can be?

e.g.

"1" or "2" or "3"....

If one could be made up by reading the first field in the filtered table and then using that to filer another table then this would be possible.

If there is a limit this would not really be a viable option since I would need upto 1000 numbers in the filter to ensure that the database produces accurate reports.

It would be much easier if there was a way to filter a table based on the contents of each record in another, filtered table.
Jan 22 '08 #2
NeoPa
32,557 Recognized Expert Moderator MVP
If you're asking "Is there a way to filter one query depending on the results of another?", then the answer is yes.

You wouldn't use OR but In() instead. Let me see if I can come up with a simple example reflecting your original question for you.

I suggest, in the mean time, you look up the In() function & subqueries (Subqueries in SQL) to get a better understanding of how it works.
Jan 22 '08 #3
NeoPa
32,557 Recognized Expert Moderator MVP
I've just noticed in your data that [Response ID]s 1 & 2 both have multiple answers for [Question ID] 2. Does this make sense?
This shouldn't effect the method to use, but thought I'd flag it anyway.
Jan 22 '08 #4
NeoPa
32,557 Recognized Expert Moderator MVP
I have assumed a table of [tblResult].
Expand|Select|Wrap|Line Numbers
  1. Response ID, Question ID, Answer ID
  2.    1             1           1
  3.    1             2           5
  4.    1             2           6
  5.    1             2           9
  6.    2             1           1
  7.    2             2           5
  8.    2             2           6
  9.    3             1           2
  10.    4             1           1
  11.    4             2           9
  12.    5             1           2
This is simply your original data rearranged for illustration. Multiple answers for the same question may well still be a problem for you, but should not effect this process.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Response ID],[Question ID],[Answer ID]
  2. FROM [tblResult]
  3. WHERE [Response ID] In(SELECT [Response ID]
  4.     FROM [tblResult]
  5.     WHERE ([Question ID]=1) AND ([Answer ID]=1))
Jan 22 '08 #5
Craggy
41 New Member
Some questions will be singe choice and others multiple.

For example a question may be "Which of the following supermarkets do you use regulary". ASDA, Tesco, M&S, Iceland

Its possible people would shop at more than one, and i would need to record that.

Now for example another question could be "how often do you shop" Regulary, rarely

What i need to be able to do basically is filer which stores people who shop regulary visit, and which stored people who shop rarely visit.

(these are completely fabricated questions by the way!)
Jan 22 '08 #6
Craggy
41 New Member
The problem i have is technically one response is covered over many records. If it was over just 1 record the filters i need would be easy.

Expand|Select|Wrap|Line Numbers
  1. Response ID, Question ID, Answer ID
  2.    1             1           1
  3.    1             2           5
  4.    1             2           6
  5.    1             2           9
  6.    2             1           1
  7.    2             2           5
  8.    2             2           6
  9.    3             1           2
  10.    4             1           1
  11.    4             2           9
  12.    5             1           2
  13.  
What i have highlited in bold is what a filter would show. in the above example this would just be showing people who shop regulary, but then all other information about these regular shoppers is lost. But i do know that Response ID 1,2 and 4 are all regular shoppers now.

I need to be able to use that data to now find out what they answered to the second question (or whichever quesiton it may be). I now want to filter out all records except the ones that have the same Response ID as the results from the first filter (1,2 and 4)

The results would be:

Expand|Select|Wrap|Line Numbers
  1. Response ID, Question ID, Answer ID
  2.    1             1           1
  3.    1             2           5
  4.    1             2           6
  5.    1             2           9
  6.    2             1           1
  7.    2             2           5
  8.    2             2           6
  9.    4             1           1
  10.    4             2           9
  11.  
Jan 22 '08 #7
Craggy
41 New Member
This probably sounds like a stupid question but where would I put the code?

Expand|Select|Wrap|Line Numbers
  1. SELECT [Response ID],[Question ID],[Answer ID]
  2. FROM [tblResult]
  3. WHERE [Response ID] In(SELECT [Response ID]
  4.     FROM [tblResult]
  5.     WHERE ([Question ID]=1) AND ([Answer ID]=1))
  6.  
  7.  
:o
Jan 22 '08 #8
Craggy
41 New Member
Here is the code re-written for my database:
Expand|Select|Wrap|Line Numbers
  1. SELECT [ResponseRespondentID],[ResponseQuestionID],[ResponseAnswer]
  2. FROM [report]
  3. WHERE [ResponseRespondentID] In (SELECT [ResponseRespondentID]
  4. FROM [report]
  5. WHERE ([ResponseAnswer]=83))
  6.  
Since there are other fields in the table (which werent really relevent to display) I assume I can change it to:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [report]
  2. WHERE [ResponseRespondentID] In (SELECT [ResponseRespondentID]
  3. FROM [report]
  4. WHERE ([ResponseAnswer]=83))
  5.  
There is no need to select the question as part of the filter criteria since the answers are unique to the question anyway. so in the case ResponseAnswer = 83 is a "yes" answer that is associated to a particular question.

I still dont quite understand where this code goes though. I tried it in the filter section in the properties tab for my form and it had no effect.

I tried creating a query but couldnt figure out where the code would go there either.
Jan 22 '08 #9
NeoPa
32,557 Recognized Expert Moderator MVP
...
Since there are other fields in the table (which werent really relevent to display) I assume I can change it to:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM [report]
  2. WHERE [ResponseRespondentID] In (SELECT [ResponseRespondentID]
  3. FROM [report]
  4. WHERE ([ResponseAnswer]=83))
looking good ;)
There is no need to select the question as part of the filter criteria since the answers are unique to the question anyway. so in the case ResponseAnswer = 83 is a "yes" answer that is associated to a particular question.
Makes sense.
I still dont quite understand where this code goes though. I tried it in the filter section in the properties tab for my form and it had no effect.

I tried creating a query but couldnt figure out where the code would go there either.
Open a new query in design mode. Select View / SQL. Paste in the SQL code you just worked out. Switch back to Design view.

Good luck, and let me know how it works out.
Jan 22 '08 #10
Craggy
41 New Member
Seems to be working!

Absolutely excellent mate. much simpler than i had expected.

Many thanks for the help!

I assume that I can put a reference to a form field in SQL as I would in VBA.
Jan 23 '08 #11
NeoPa
32,557 Recognized Expert Moderator MVP
No problems. Glad it helped.
Try that out (referring to form controls from within SQL). Certainly I would expect any SQL code at least to require a full reference (it's not run "within" any object after all), but I'm pretty sure it can work. See Referring to Items on a Sub-Form for details on form control referencing.
Jan 23 '08 #12
Craggy
41 New Member
This works perfectly.

I can now have a form with linked dropdowns to select the question set, the questions within that set and finally the answers associated with the question - and filter the results accordingly.

I could probably take that further but dumping that data into excell then doing pivot tables seems to work well enough not to bother!

Thanks again!
Jan 24 '08 #13
NeoPa
32,557 Recognized Expert Moderator MVP
Our pleasure :)
Always appreciate a response to let us know it worked though - thanks.
Jan 24 '08 #14

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

Similar topics

3
5879
by: Marcus | last post by:
Hi I have a very complex sql query and a explain plan. I found there is a full table scan in ID=9 9 8 TABLE ACCESS (FULL) OF 'F_LOTTXNHIST' (Cost=84573 Card=185892...
1
1811
by: shumaker | last post by:
I'm trying to defeat persistant filters with the following code in Close, and also in Unload: Private Sub Form_Close() DoCmd.RunCommand acCmdRemoveFilterSort Me.FilterOn = False Me.OrderByOn =...
4
11280
by: Aaron | last post by:
Hello all. I am trying to avoid my users from saving filters. The fact is that after they use or change a filter, when closing the form Access would ask: "Do you want to save changes to the...
2
2331
by: mkiger | last post by:
Hey guys, I've never seen a dataview.rowFilter example that was anything more than something like "id = 100" or something like that. I'm trying to right one (in asp.net/vb.net) that looks like...
6
6335
by: TJO | last post by:
Below is some sample code that fades div tags that is not working in IE 6.0.29 on xp sp2. Can anyone help see why the if(ie5) document.getElementById(divID).filters.alpha.opacity lines are not...
1
1756
by: Dieter Vanderelst | last post by:
Hello, I'm trying to access the Filters-Dll provided by the filters-project (http://filters.sourceforge.net/index.htm). Following the advice I got from the Python list -thank you for that-, I...
0
1682
by: kucol | last post by:
Hi guys, I wanted to ask you for help as I am struggling with it second evening already... I have got tables DEVICES and PARTS. One device can consist of multiple parts. But... I have...
5
2781
by: favor08 | last post by:
have a mainform called PendingsMain and a subform called PendingsSub. You can filter the subform by different filters and this works fine. i want to create a report that will print out the...
35
3469
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
2308
by: CatchSandeepVaid | last post by:
We all know that one-to-one associations are non-lazly fetched but during this fetching the filters are not applied. I debugged hibernate code and found that hibernate finally calls...
0
7087
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
7281
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
7334
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...
1
6993
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
7462
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...
0
5579
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,...
0
3168
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...
0
1514
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 ...
0
383
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...

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.