Results 1 to 5 of 5
  1. #1
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91

    How to filter data using checkboxes?

    Could someone just provide an example of how to code a checkbox. I have checkboxes on Form A with a category A, B, and C. I want to be able to check one or multiple categories to filter the list box to that specific results in Form B. If left unchecked then all results show. How would you write such coding?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,526
    in a continuous form, when user clicks Filter button, check all the boxes to build the where clause:
    Code:
    '----------------
    sub btnFilter_click()
    '----------------
    dim sWhere as string 
    sWhere = "1=1"
    if chkSmokers.value then sWhere = sWhere & " and [smokers]= true"
    if chkAdults.value then sWhere = sWhere & " and [Adult]= true"
    if not IsNUll(cboZip) then sWhere = sWhere & " and [ZipCode]='" & cboZip & "'"
    
    If sWhere = "1=1" Then
      Me.FilterOn = False
    Else
      Me.Filter = sWhere
      Me.FilterOn = True
    End If
    end sub

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Cannot give a good answer because the question is too vague.

    What I can determine is there are two forms involved, "FormA" and "FormB".
    "FormA" has 3 check boxes to select up to 3 categories. You want to be able to check 1 or more check boxes to filter on one or more categories (fields?).
    This filter is to be applied to a list box on "FormB".


    There are no object names, no examples of data, no categories. When is "FormB" opened? Is "FormA" still open when "FormB" opens??

    Very hard to write code when nothing is defined...

  4. #4
    qwerty is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    91
    Quote Originally Posted by ssanfu View Post
    Cannot give a good answer because the question is too vague.

    What I can determine is there are two forms involved, "FormA" and "FormB".
    "FormA" has 3 check boxes to select up to 3 categories. You want to be able to check 1 or more check boxes to filter on one or more categories (fields?).
    This filter is to be applied to a list box on "FormB".


    There are no object names, no examples of data, no categories. When is "FormB" opened? Is "FormA" still open when "FormB" opens??

    Very hard to write code when nothing is defined...
    Almost correct, in the query there 2 tables that relate by the scientific names. One table has a criterias relate to the scientific name the other table is by location. The checkboxes control source is with the criteria. I want to be able to filter the related the sciname in the location table based on fields in the criteria that equal to -1. The scientific appear in a listbox on Form B, if left unchecked I want all species showing.

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Again, no field names, no table names, no images of the relationship window, no images of the forms or form names....

    Maybe post an example dB with the tables and the forms involves.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Select all checkboxes and apply current filter
    By cbmorehouse in forum Modules
    Replies: 9
    Last Post: 08-21-2018, 07:33 PM
  2. VBA for Report Filter based on Form Checkboxes
    By Kirsti in forum Programming
    Replies: 11
    Last Post: 04-23-2014, 04:52 PM
  3. Filter Checkboxes
    By lewis1682 in forum Programming
    Replies: 3
    Last Post: 09-11-2013, 11:19 AM
  4. Filter Query based upon Checkboxes
    By olinms01 in forum Queries
    Replies: 2
    Last Post: 01-21-2013, 11:38 AM
  5. Filter records based on multiple checkboxes
    By kbremner in forum Forms
    Replies: 2
    Last Post: 01-18-2011, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums