Results 1 to 5 of 5
  1. #1
    CRobledo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    26

    filter Combo box values based on form Checkbox


    I have a form with a combobox and a checkbox. I would like the dropdown values of the combobox to be filtered based on whether the checkbox is checked or not. The values are in a table named ChemicalList under the field name PruductName and there is a checkbox next to each name in that table. I would like that if the checkbox is checked in the form then all the records with a checked box next to them be returned to the combo box. if not then return all.

    please help

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Make 2 queries, qsAll and qsChecked. The default is qsAll.
    When user checks the box, swap out the cbo query.

    Code:
    sub chkBox_afterupdate()
    If chkBox.value then
       CboBox.rowsource = "qsChecked"
    else
      CboBox.rowsource = "qsAll"
    End if
    end sub

  3. #3
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Maybe someone knows how to do this with a query, but I don't see a way to totally eliminate query criteria in one case, but use it in another by writing some sort of IIF expression. So my solution would be a coded one, on the combo Enter event. In my experience, the Click event, while logical, is flaky. So it would be something like

    Code:
    If Me.chkMyCheck = False Then
    Me.cmbMyCombo.RowSource = "SELECT ChemicalList.PruductName FROM ChemicalList"
    Else
    Me.cmbMyCombo.RowSource = "SELECT ChemicalList.PruductName FROM ChemicalList WHERE ChemicalList.myCheckedField = True"
    End If
    Obviously you have to substitute your own field and control names.
    Last edited by Micron; 03-15-2017 at 06:38 PM. Reason: correction
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    CRobledo is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2016
    Posts
    26
    thanks! that worked great!! I added multiple cboboxes what syntax do i need to use to add more to the code you gave me?

  5. #5
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    you had 2 proposals, so to whom are you referring? If me, then you need one for each checkbox, or if there's more than say 5 or 6 and they're all doing the same thing, I might create a function and pass parameters to it. Certainly the checkbox name for one, but you'd probably need to pass something that told it what sql to create. That function could then check for the second parameter value and create and return the appropriate sql. Kind of like
    strSql = CreateSqlControlName, "ChemList" (where ControlName is the actual checkbox control object and ChemList denotes a sql for chemical list)
    then the function processes based on those 2 parameters
    Public Function CreateSql (ctl As Control, Flag As String)
    'do stuff
    End Function
    I just wasted a few precious minutes if you weren't referring to me!
    Last edited by Micron; 03-16-2017 at 03:30 PM. Reason: clarification

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

Similar Threads

  1. Replies: 11
    Last Post: 09-03-2015, 11:12 AM
  2. Replies: 3
    Last Post: 06-18-2014, 10:40 AM
  3. Replies: 1
    Last Post: 10-01-2013, 09:25 PM
  4. Replies: 7
    Last Post: 12-12-2012, 03:14 PM
  5. Replies: 1
    Last Post: 04-27-2010, 09:30 PM

Tags for this Thread

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