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

How to search query for a check box

18
There are some fields that have check box. Now, how do I search a query such that it will prompt the user to enter Yes or No, so that when I select Yes it will give me the records that are checked and vice-versa for No.

Thank you
Hulas
Apr 6 '08 #1
7 4563
NeoPa
32,556 Expert Mod 16PB
As this doesn't really make sense as written, I'll guess that you're asking about how to select records (using a query) where the user has clicked on a field which shows as a Checkbox in a form.

Assuming the CheckBox field is called [chkYN], you would use :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE [chkYN]
...to find records which are checked and :
Expand|Select|Wrap|Line Numbers
  1. ...
  2. WHERE Not [chkYN]
...to find records which are NOT checked.

Does this answer what you were trying to ask?
Apr 6 '08 #2
Hulas
18
Sorry for not being so descriptive about that. I have a table whose one of the field is a check box. Now, what I have done is I have created a form that has a list box with 'Yes' or 'No'. The form also has a button call 'Ok'. Now, how should I programme the 'OK' button such that if I select 'Yes' from the list box than it will give me all the records for the field whose check box are selected. Likewise, if I select 'No' from the list box than it will give me all the records for the field whose records are not selected. Again, if I select both 'Yes' and 'No' than it should give me all the records.

Thank you for your help
Hulas
Apr 7 '08 #3
NeoPa
32,556 Expert Mod 16PB
This really rather depends on what "it" is.

You use "it" throughout your explanation, yet never describe what "it" is.

If "it" is a report (or form) then you need to set up and pass a filter, yet if it is a query you will need to think again about your interface.
Apr 7 '08 #4
PianoMan64
374 Expert 256MB
Sorry for not being so descriptive about that. I have a table whose one of the field is a check box. Now, what I have done is I have created a form that has a list box with 'Yes' or 'No'. The form also has a button call 'Ok'. Now, how should I programme the 'OK' button such that if I select 'Yes' from the list box than it will give me all the records for the field whose check box are selected. Likewise, if I select 'No' from the list box than it will give me all the records for the field whose records are not selected. Again, if I select both 'Yes' and 'No' than it should give me all the records.

Thank you for your help
Hulas
So Hula,

Let me see if I understand your question, you have a list control box that has a list of results in it. It has both Yes and No Items in it. You want to be able to select a Combo box control with either Yes or No in it and then have th list control display the resulting records accordingly?

If so, then here's what you're going to need to do:

Like explained before, you're going to have to build a SELECT SQL String in the RowSource Property of the List Control Box.

Example:

Assuming the List Control named was "lstList" and the Combo Box was named "cboCriteria" then you would do something like this in Code section of the form.

Expand|Select|Wrap|Line Numbers
  1.  
  2. If me.cboCriteria = "Yes" Then
  3. me.lstList.rowsource = "SELECT * FROM [TableName] WHERE chkBox = True"
  4. Else
  5. me.lstList.rowsouce = "SELECT * FROM [TableName] WHERE chkBox = False"
  6. End if
  7. me.lstList.Requery
  8. me.repaint
  9.  
Paste this into the OnChange Event

Hope that helps,

Joe P.
Apr 7 '08 #5
Hulas
18
No, I don't think I have really found what I need. I will try to be more descriptive and let's see if that works. I have a table 'FoodandBeverage' and this table has a field called 'Restaurant' whose data type is Yes/No. Now, I want to set up a form that has a list box with (yes or no), such that if I select 'Yes' from the list and press the 'OK' button I should get all the records whose check boxes are checked. Likewise, I if I select 'No' from the list and press the 'OK' button I should get all the records whose check boxes are not-checked. I don't care if it pulls the records from a query or table.

Thank you guys for your help.
Hulas
Apr 7 '08 #6
NeoPa
32,556 Expert Mod 16PB
I'm pretty sure I understand the logic of the requirement Hulas. What I still don't know is how you intend to process the data.

A table was never an option. A query or report or form are the options. If you want to use a form or report then you must have one to refer to.

Queries are harder to apply the necessary logic to as Access isn't very friendly in that area. Reports and forms on the other hand are relatively straightforward and involve passing a filter in the call to open them.
Apr 7 '08 #7
NeoPa
32,556 Expert Mod 16PB
I will assume that you are happy to design a report for this and that it's called [rptFnB] with a boolean (Yes/No) field called [Restaurant].
The ListBox is called [lstYN] and the first line is "Yes", the second line "No".
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdOK_Click()
  2.   Dim strFilter As String
  3.   Dim intIx As Integer
  4.  
  5.   For intIx = 0 To Me.lstYN.ListCount - 1
  6.     If Me.lstYN.Selected(intIx) Then _
  7.       strFilter = strFilter & Me.lstYN.Column(0, intIx)
  8.   Next intIx
  9.   Select Case strFilter
  10.   Case ""
  11.     'Potentially use a MsgBox() here
  12.     Exit Sub
  13.   Case "YesNo"
  14.     strFilter = ""
  15.   Case Else
  16.     strFilter = IIf(strFilter = "Yes", "", "Not ") & "[Restaurant]"
  17.   End Select
  18.   Call DoCmd.OpenReport("rptFnB",acViewPreview,,strFilter)
  19. End Sub
Your options would be a lot simpler if you used two separate CheckBoxes on your form instead of a ListBox though. The query would be an option then. I suppose this just illustrates that it's helpful if you just answer the questions we ask rather than trying to explain to us why they're not important (It'll certainly save me having to waste so much time writing every option down). Hey-ho - I'm sure you'll learn.
Apr 7 '08 #8

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

Similar topics

1
by: J P Singh | last post by:
Hi All I have been asked to build a search page to allow users to search the database. The issue is that the search page in ASP must mirror out existing search screen on the VB application. I...
8
by: Scott M. | last post by:
Sorry if this isn't the right NG for this.... What is involved in providing a small text box and submit button on my homepage that will provide site searching capabilities? I know that Index...
4
by: shapper | last post by:
Hello, I am working on a web site which displays various information from a database: 1. Text articles 2. PDF files for download. The links and displayed information are also retrieved...
4
by: subash | last post by:
Please check this query $query = "SELECT a.intNEHID AS id,a.vchNEHTitle AS title" . "\n FROM tbNews AS a, tbNews AS b,tbMinistry AS c" . "\n WHERE (a.vchNEHDesc LIKE...
2
by: caine | last post by:
I'm doing a search application for my project. My code can prompt alert popup window when the user doesn't key in any keywords. However, if the user keys in any keywords, it juz return "Please...
1
Merlin1857
by: Merlin1857 | last post by:
How to search multiple fields using ASP A major issue for me when I first started writing in VB Script was constructing the ability to search a table using multiple field input from a form and...
2
by: WesternCanuk | last post by:
Hello all. i'm new to mysql and a but of advice would be fantastic. I"m building a PHP website where i'm have problems getting my search query to work. I have built the search using AND and OR but...
3
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank...
5
by: th1982 | last post by:
HI All I have a search page' s result which view 3results/per page,but my "next" link to view next page is not working. Here is my code : <?php // Get the search variable from URL ...
18
by: luke noob | last post by:
can some one please help me adapt my script so that i can search for multiple words within my database, my keywords feild looks something like this.... Big Teddie Bear Collection Tiny Small...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
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...

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.