473,394 Members | 1,481 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.

How to filter Rowsource Results Using Yes/No?

I have a list box which I want to populate from a table that has lots of Yes/No values (Skills and Training, etc), and I want to be able to filter this box to show only the names of the people who have the right skills/qualifications for the job we need them on.

So, basically, I have set up the Form with a load of check boxes to provide the yes/No inputs. So far so good, however, how do I get it to ignore any check boxes I haven't checked, and only query using those I have?
Nov 17 '10 #1
8 5031
NeoPa
32,556 Expert Mod 16PB
Are you looking for records where any of the fields are checked or where all of them are?
Nov 17 '10 #2
NeoPa
32,556 Expert Mod 16PB
Actually, the solutions are similar enough.

You don't provide any details so I will assume you have boolean fields called Q1, Q2, Q3, etc to reflect the various qualifications you refer to, and that you are looking to return some typical fields.

Expand|Select|Wrap|Line Numbers
  1. SELECT [GivenName]
  2.      , [Initials]
  3.      , [Surname]
  4. FROM   [YourTable]
  5. WHERE  [Q1]
  6.    OR  [Q2]
  7.    OR  [Q3]
  8.    OR  ...
This SQL above selects the records where any of the qualification fields is TRUE.

Expand|Select|Wrap|Line Numbers
  1. SELECT [GivenName]
  2.      , [Initials]
  3.      , [Surname]
  4. FROM   [YourTable]
  5. WHERE  [Q1]
  6.   AND  [Q2]
  7.   AND  [Q3]
  8.   AND  ...
This SQL above selects the records where all of the qualification fields are TRUE.
Nov 17 '10 #3
Unfortunately the answer is both. For example I would want it to select the record where Q1 and Q3 are true, but ignore the rest, then the next time Q2, Q4 and Q7.. and so on.

Basically, so you can select those persons with the right skills for the job, which the OR function would do, but only for one skill, not multiples.
Nov 18 '10 #4
NeoPa
32,556 Expert Mod 16PB
But you get the concepts right?

A boolean value doesn't need a comparison operator, as it is already boolean, which is what is returned by a comparison. [SomeField] >= 7 returns a boolean value of either TRUE or FALSE. A boolean variable is already boolean so doesn't need any such thing to be used where booleans are required (in a WHERE clause for instance).

Where you have multiple qualifications required then link them together with AND keywords. Where multiple sets of qualifications are possible alternatives then link any individual or sets of qualifications together using the OR keyword. When a set of qualifications is used as a possible alternative, it is important to encapsulate the set within parentheses ().
Nov 18 '10 #5
In the end, I came up with this method:
Expand|Select|Wrap|Line Numbers
  1. Dim Driver As String
  2. If DriverCheck.Value = False Then
  3. Driver = ""
  4. Else
  5. Driver = "[Driver] = [Forms]![FitterSkillSelect]![DriverCheck] AND"
  6. End If
  7.  
For each of the checkboxes and then
Expand|Select|Wrap|Line Numbers
  1. SearchFitter.RowSource = "SELECT [FitterName] FROM [tblFittersLocal] WHERE  " & Driver & "[ID] > 0"
  2.  
Obviously [ID]>0 is entirely pointless as all have an ID of more than 0, but it just stops there being an AND value stuck on the end.
And this worked well apart from the fact that it wouldn't work unless the checkbox had been checked and unchecked before running the code. So I did the following

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.  
  3. [DriverCheck] = True
  4. [DriverCheck] = False
  5. End Sub
  6.  
Any ideas why I would need to do this, or is this just one of access's little quirks?
Nov 19 '10 #6
NeoPa
32,556 Expert Mod 16PB
It's hard to be sure James, as you don't indicate where most of your code runs, but let me guess :

Your first snippet of code, and similar ones for other controls, are found in AfterUpdate event procedures for the various controls. If the controls are never set then Driver could be undefined, and therefore result in invalid SQL being assigned to SearchFitter.RowSource. As I say, just a guess.

Assuming that each control is a CheckBox, and setting it means that the related boolean is required in the records we're looking for (and cleared means we can simply ignore), then I would do things the following way :
  1. Start by setting the RowSource string to the simpler SELECT [FitterName] FROM [tblFittersLocal]. From here we work with a Filter string exclusively so the RowSource needd never be changed.
  2. Ensure that the Filter string of the design matches the boolean settings set as default. If all are cleared then this would mean an empty Filter string of course, but if any are set then this should be reflected in the form's designed Filter string.
  3. Each CheckBox's AfterUpdate event procedure should simply call a new procedure we will show below, called UpdateFilter().
  4. Enter the following procedure, within the form's associated module, as :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub UpdateFilter()
    2.     Dim strFilter As String
    3.  
    4.     With Me
    5.         If .DriverCheck Then _
    6.             strFilter = strFilter & " AND ([Driver])"
    7.         If .NextCheck Then _
    8.             strFilter = strFilter & " AND ([Next])"
    9.         'Repeat for all CeckBoxes cum boolean fields in the record
    10.  
    11.         With .SearchFitter
    12.             .FilterOn = (strFilter > "")
    13.             If .FilterOn Then .Filter = Mid(strFilter, 6)
    14.         End With
    15.     End With
    16. End Sub
I would suggest that, when you get this working, you have a look at the code and see if you can see why it does. I'm happy to answer any questions on it, but things like this come up all the time in form work, so it's well worth understanding.
Nov 19 '10 #7
NeoPa
32,556 Expert Mod 16PB
Having just reread through to see if I could tie in some of the things I didn't understand, I now realise that SearchFitter is a ListBox control, and not another form. I should have realised when I was putting that together as it appeared to be related to Me (That was my best guess anyway). Now I reread the OP I can see it is indeed a ListBox control on the form. Give me a few minutes and I'll come up with a version of the code that is very similar, but directed towards a control on a form rather than on a form.
Nov 19 '10 #8
NeoPa
32,556 Expert Mod 16PB
Right. A new list of instructions for handling a ListBox (or ComboBox even) :

Assuming that each control is a CheckBox, and setting it means that the related boolean is required in the records we're looking for (and cleared means we can simply ignore), then I would do things the following way :
  1. Start by setting the RowSource string (in the design) to match the boolean settings set as default in the form. If all are cleared then this would mean the basic SELECT string, but if any are set then this should be reflected as a WHERE clause.
  2. Each CheckBox's AfterUpdate event procedure should simply call a new procedure we will show below, called UpdateFilter().
  3. Enter the following procedure, within the form's associated module, as :
    Expand|Select|Wrap|Line Numbers
    1. Private Sub UpdateFilter()
    2.     Dim strSQL As String
    3.  
    4.     With Me
    5.         If .DriverCheck Then strSQL = strSQL & " AND ([Driver])"
    6.         If .NextCheck Then strSQL = strSQL & " AND ([Next])"
    7.         'Repeat for all CheckBoxes / boolean field pairings in the record
    8.  
    9.         If strSQL > "" Then strSQL = " WHERE " & Mid(strSQL, 6)
    10.         strSQL = "SELECT [FitterName] FROM [tblFittersLocal]" & strSQL
    11.         With .SearchFitter
    12.             .RowSource = strSQL
    13.             Call .Requery
    14.         End With
    15.     End With
    16. End Sub
I would suggest that, when you get this working, you have a look at the code and see if you can see why it does. I'm happy to answer any questions on it, but things like this come up all the time in form work, so it's well worth understanding.
Nov 19 '10 #9

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

Similar topics

3
by: mark | r | last post by:
anyone have any tips on creating a search results filter to provide the best matches first? we're using an access database as part of a very small custom CMS, and we need to site search function...
2
by: Terri | last post by:
I know formatting should be handled in the client app and not in SQL Server but this is the situation I must develop in so any help would be appreciated. I'm running the following in Query...
0
by: Irena | last post by:
Hi all there, Form time to time, I go back to this project of mine that drives me nuts, now. Sometimes ago, I have been suggested to use DAO insted of ADO for getting the "ROWSOURCE" property...
9
by: Lukman | last post by:
Hi, Do you know how to display ASP.NET result (database result from ADO.NET) using Excel in IE ? Thanks,
3
by: iamguyster | last post by:
Hi, I have an exercise I need to give to my pupils (I'm a teacher!) and I am trying to get a query working preferably using the query design view, without having to edit the SQL. The query involves...
5
by: mikevde | last post by:
Hi, Can anyone confirm whether it is possible to: a) use subqueries in mySQL b) use DISTINCT TOP in mySQL? I am trying to find a way to return the top 5 results in my table. For simplicity...
1
by: datasec23 | last post by:
Hi... I really appreciate your help with my question, I am pulling my hair out on this. I have not been able to find an answer on the other posts. I am using Access 2000. I have a form that...
3
manoj9849967222
by: manoj9849967222 | last post by:
Hi All I have a great problem. Is there a way to filter records using dates. I have a table called sales. now i want to filter record say from 1/1/2006 to 1/1/2007. which would show me the sales...
1
by: itssri.srinivas | last post by:
Hi, Below is the XSL syntax to filter output from XML file based on single value:- <xsl:for-each select="catalog/cd"> so, above code displays the text of the CD elements whose artist is...
4
by: novoselent | last post by:
This seems like it should be an easy thing, but I think I'm missing something simple here...or I'm just going about it all wrong... Using Access 2003 I have a form that lists vehicle service...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.