473,493 Members | 2,265 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Query on Yes/No to show all records

4 New Member
Hi all.

I have run into a problem with my database. It seems something that should be easy to do but although I've searched a lot I can't find a solution.

I have a query that takes the filtering values from a form. In the top part I have a combobox for each field which I want to filter and in the bottom part the result from the query. This way when a user selects a value in the combo the query auto updates and shows the results applying the filter in "real time".

The problema is with a Yes/No field. With all the other fields the default value is "*" so I can see all the records until I select a filter in the form. However in the yes/no field I can't select an "*" value. I'm forced to see all the records with a Yes value in that field or the ones with a No but never all of them.

It's there an easy way I can tell the query to show all the fields with Yes OR all the fields with No OR all the fields whatever the value?

Thank you very much in advance!
Nov 7 '11 #1
4 10699
ADezii
8,834 Recognized Expert Expert
You could create a Query showing ALL Records, then modify the SQL building a Criteria String, then Open the Query. Let's suppose that:
  1. I have an Employees Table named Employees.
  2. I have a [Retired] (Yes/No) Field in the Employees Table.
  3. I have a Combo Box on the Form (cboRetired) displaying the following 3 Options:
    1. (ALL) - ALL Employees, retired or not.
    2. Yes - Retired Employees only
    3. No - Employees who are not Retired.
  4. The following Code will modify the SQL of qryEmployees to show either of the 3 Options above, or all Employees should none be selected.
  5. Other Criteria, of course, can be build into strBuild.
    Expand|Select|Wrap|Line Numbers
    1. Dim strBuild As String
    2. Dim qdf As DAO.QueryDef
    3.  
    4. Select Case Me![cboRetired]
    5.   Case "(All)"
    6.     strBuild = "[Retired] = True Or [Retired] = False"
    7.   Case "Yes"
    8.      strBuild = "[Retired] = True"
    9.   Case "No"
    10.      strBuild = "[Retired] = False"
    11.   Case Else
    12.     strBuild = "[Retired] = True Or [Retired] = False"
    13. End Select
    14.  
    15. Set qdf = CurrentDb.QueryDefs("qryEmployees")
    16.  
    17. qdf.SQL = "SELECT * FROM Employees WHERE " & strBuild
    18.  
    19. DoCmd.OpenQuery "qryEmployees", acViewNormal, acReadOnly
  6. I hope this is what you are looking for.
Nov 7 '11 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Essentially No. There is no way of using a wildcard or equivalent with numbers.

You can get around it by checking if the control is actually even set in your filter, but you'd need to handle that in your design.
Nov 12 '11 #3
David Scott
4 New Member
Thank you for your answers.

Finally I could solve it using a simple "trick". Maybe it's not so elegant but it works like a charm. :)

In my query I applied the val() function to the boolean field. As you now as a result it gives back "0" if the boolean is False and "-1" if it's True. The good thing is that when converted to a value it lets me search using "*".

Then I changed the form so when the user selects a True value the query searches for "-1". When he selects a False value the query searches for "0". At last if he selects "All" the query searches for "*" (this is also the default value). As I said before it works perfectly and gives the exact result I needed.

Thank you again for your help. Both answers made me think about it and find this solution.
Nov 16 '11 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Good thinking David.

With that in mind, and avoiding the call of a function for each record (as your current solution does), thus making it process more efficiently, you might like to try an alternative of :
Expand|Select|Wrap|Line Numbers
  1. WHERE ([YNField] Between True And False)
Your solution got me thinking in the right direction ;-)
Nov 16 '11 #5

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

Similar topics

1
2064
by: (Pete Cresswell) | last post by:
..DefaultView = Continuous Forms ..RecordSource = a query. While the form & subform are open, I can open up the .RecordSource query and see five records. If I insert a record, then re-open...
6
8132
by: Sven Pran | last post by:
Probably the answer is there just in front of me only awaiting me to discover it, but: 1: I want to build a query that returns all records in one table for which there is no successful "join"...
4
1464
by: mugen | last post by:
hi.. have a continious form. there are some records that i'd like to omit from showing in the form. is it possible to set a check box that if set to true will make sure that the record is not...
15
1895
by: Joachim | last post by:
Hi, Als a beginner, I am looking for a way to show records My code is Private sub Connection( Dim odbconn_Pro As OleDbConnectio Dim odbcomm_Pro As OleDbComman Dim odbdare_Pro As...
2
8051
by: Zeljko | last post by:
I'm creating Address book. Header of the main form (frmAddress) contains combo box (cboFilter) to filter records by Occupation on main Form(Ocupation1). That's working. Combo box also have "Show...
5
3395
by: binky | last post by:
Question for all you SQL gurus out there. I have a (seemingly) complex query to write, and since I'm just learning SQL server, am not sure how to go about it. Tables: t_trans t_account All...
11
18049
by: bikefixxer | last post by:
I'm a beginner with Access and am using the 2007 version on XP. I've created a database that keeps track of employee hours where I work. Everything has worked fine until we recently hired someone...
1
6110
by: Steve | last post by:
I have to tables Table1 IMS_ID IMS_Name IMS_Descript Table2 P_IMS_ID P_IMS_Name P_IMS_Descript
2
2443
by: nspader | last post by:
OK, I am pulling my hair out on this one. It seems like it should be so simple and I cannot seem to find the answer. I am using Access 2000 on Windows 2000. I have two tables set up. Table...
5
4186
by: rushtona | last post by:
I'm trying to build an Access Query that will give me the year and the total catch, even if there was no catch. The problem is if there was no catch for a certain year the query is not showing that...
0
7119
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
6989
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
7195
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
7367
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
5453
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,...
1
4889
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...
0
4579
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...
0
3088
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
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.