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

Extracting records based only on check boxes ticked

Fspinelli
I have a table with various information (company name, address, etc.) plus five check boxes. One or more of those check boxes may be ticked as it relays a type of status to the end user.

I have a query based on the table's five check boxes plus the Company Name and Record ID #. In the Criteria area I have the word True (no quotes) under each of the check boxes on seperate rows.

I have an unbound form (frmCheckboxes) with the 5 check boxes (same names). Within this form is a subform (sfCheckboxes_Results). This subform is "supposed" to display all records with only the check boxes ticked on the form...

...However, I am getting all records with any check boxes ticked.

I have a terrible feeling there should be some And/If/or and Elses in the code some where. I just don't know how to write it.

Basically:
If CB1 and CB3 are checked then only display records in the subform who's CBs 1 and 3 are ticked. Else don't display anything (in the subform).

I'm lost on quering check boxes.

Please help.

Thank you and wishing everyone a VERY Happy, Healthy, and Prosperous New Year!
Dec 31 '10 #1
3 6299
Mr Key
132 100+
I dont see the relationships of your checkBoxes and records in your post!
May you post a sample of your database or explain in details about your problem.
Dec 31 '10 #2
ADezii
8,834 Expert 8TB
  1. This is a Multi-Step process, but first a couple of Assumptions:
    1. All Check Boxes on the Form, namely CB1...CB5 are 'Unbound', and there are no other Check Boxes aside from these.
    2. The Check Box Names, CB1...CB5, are exactly the same as the Field Names in the underlying Table.
  2. A For Each...Next Loop checks every Control on the Form and:
    1. Sees if it is a Check Box.
    2. If it is a Check Box, then sees if it is selected (Checked).
    3. If it is a Check Box, and it is Checked, dynamically builds a partial SQL String with those selected Check Boxes in it.
  3. The Code next checks to see if there are any Records in the Table that match the specified Criteria, namely any Check Box(es) checked.
  4. If there are any Matching Records the Record Source of the Sub-Form is modified based on the newly created SQL Statement.
  5. The Code is posted below; simply change the Name of the strTableName variable to reflect your own Table Name.
  6. Any questions, feel free to ask.
    Expand|Select|Wrap|Line Numbers
    1. Dim ctl As Control
    2. Dim strBuild As String
    3. Dim strSQL As String
    4. Dim strTableName As String
    5.  
    6. 'Substitute your Table Name here
    7. strTableName = "tblEmployees"
    8.  
    9. strSQL = "SELECT * FROM " & strTableName & " WHERE "
    10.  
    11. For Each ctl In Me.Controls
    12.   If ctl.ControlType = acCheckBox Then
    13.     If ctl.Value Then       'Is Control Checked?
    14.       strBuild = strBuild & ctl.Name & " = True AND "
    15.     End If
    16.   End If
    17. Next
    18.  
    19. If Len(strBuild) > 0 Then
    20.   'Do any Records exist that match the Criteria?
    21.   If DCount("*", strTableName, Left$(strBuild, Len(strBuild) - 5)) > 0 Then
    22.     Forms!frmCheckBoxes!subfEmployees.Form.RecordSource = strSQL & _
    23.           Left$(strBuild, Len(strBuild) - 5) & ";"    'Remove trailing ' AND '
    24.   End If
    25. End If
Dec 31 '10 #3
i got it! I had to put this code in the query:

IIf([forms]![frmCB]![cb1],[FoF]=True,True)

I had CB1,2,3,4,5 checked but next to them I inserted a colum and entered that code above for each check box (CB). Not checked for viewing.

CB1 also = FoF so when I clicked on CB1 all records that had their FoF (cb1) ticked would show. Same with if I clicked on FoF (cb1) and NHF (cb2) - only records with those CBs ticked would come up.

So thank you one and all! Great learning experience!
Dec 31 '10 #4

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

Similar topics

13
by: Adrian Parker | last post by:
I have a PHP generated page which displays X many records. Each record has a checkbox preceding it. The user checks several checkboxes, and hits a delete button. All the corresponding records...
17
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part...
4
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
1
by: Rado | last post by:
Hi All, This might quite simple process for some but I am finding it really difficult to do. What is required is not a standard Duplicate query but a variation on it. For example I have...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
0
by: Karl Roes | last post by:
I'm still having trouble posting follow-ups. :-( "Unable to retrieve message 7cc66112.0501041919.3a6628b4@posting.google.com" Now Turtle wrote "You'll need an extra field in the table...
1
by: Kirsty Ryder | last post by:
Hi In my report I have data grouped by station. Some of the records have check boxes checked to indicate whether the station was declared available or unavailable at the time of incident, and...
5
by: jimc52 | last post by:
Hello Everyone: I am hoping one of the gurus here will give me some help. I have designed a form with some check boxes. I put the checkboxes there on the form so later I could use them as flags on...
19
by: questionit | last post by:
If you have so many check-boxes on a form . If you want to see if atleast 2 of them have been ticked. Do you have to loop through each of it - it would be difficult since each check-box has a...
7
by: PANGAWD | last post by:
Hi!!! I´m used to search your forum all the time if I have any problem in Java, C, etc,etc... and I always found an answer, but this time I can´t... I know that this must be a simple answer,...
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?
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
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
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
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
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
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...

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.