Results 1 to 10 of 10
  1. #1
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93

    Combo box selection


    Hello everyone I have a query that is being filtered based on the value of a combo box in another form. So in the design view of the query I have something like this [Forms]![FormName]![ComboBoxName] in the Criteria of the field I am filtering my query with. The combo box in the form is an unbounded control that picks its value from another table. So once the user clicks a command button on the form, a report is being generated based on the filtered query. I need to give my users and option to select a value from the combo box that will return the underlying query of the report unfiltered and I don’t want to use blank and the option should be user friendly (not something like null)

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    in your criteria

    WHERE somefield = [Forms]![FormName]![ComboBoxName] OR [Forms]![FormName]![ComboBoxName] is null

    Or if you include 'All' in your combo rowsource

    WHERE somefield = [Forms]![FormName]![ComboBoxName] OR [Forms]![FormName]![ComboBoxName] ="All"

  3. #3
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thanks for your reply Ajax
    The combo box picks its values from a table, Do I have to add “All” to my rowsource table ? can I add “All” to the values that are displayed in my combo box and not add that value to my table or change the rowsource of my combo box ?

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I've never used "All" as Ajax is suggesting, I am interested to hear how (s)he does it. I usually add an option button for ALL and then in the query say OR Forms!FormName!Option=True.

  5. #5
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thanks for your reply aytee111
    Could you please elaborate on your answer, how do you combine the use of the option button with the combo box ? and what do you do if you had more than one combo box that is used to feed the query in multiple criteria fields ?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Here's a method of adding all as a choice:

    http://access.mvps.org/access/forms/frm0043.htm

    you can combine that with the null method of returning all records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    SunTop is offline Advanced Beginner
    Windows 8 Access 2016
    Join Date
    Aug 2016
    Posts
    93
    Thank you pbaldy for your reply
    That is exactly what I was searching for

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    @aytee111
    I've never used "All" as Ajax is suggesting, I am interested to hear how (s)he does it.
    - I'm a he

    when using a table as a rowsource. For a straight list you would use something like

    Code:
    SELECT fld1, 1 as SortOrder
    FROM myTable
    UNION SELECT "All", 0 FROM myTable
    ORDER BY sortorder, fld1
    or where there are ID's involved, something like

    Code:
    SELECT PK, fld1, 1 as SortOrder
    FROM myTable
    UNION SELECT 0, "All", 0 FROM myTable
    ORDER BY sortorder, fld1
    in which case your criteria would be

    WHERE somefield = [Forms]![FormName]![ComboBoxName] OR [Forms]![FormName]![ComboBoxName] = 0

    The dummy sortorder field is required to ensure that All appears at the top (or the bottom if you change it's value to 2 for the second union query), regardless of the sorting for the rest of the values (I presume you wouldn't want it to appear between Alaska and Arizona). It does not need to be referenced in the combo or listbox so the column count would remain unchanged.

    Edit: just seen Paul's link, you can substitute a null for 0 in the second example

    ...
    ...
    UNION SELECT Null, "All", 0 FROM myTable
    ...

  10. #10
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Of course! That's brilliant, and very useful. Thanks Mr Ajax

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

Similar Threads

  1. Replies: 7
    Last Post: 03-30-2015, 10:04 AM
  2. Replies: 5
    Last Post: 04-09-2014, 06:57 PM
  3. Replies: 6
    Last Post: 02-19-2014, 11:11 AM
  4. Replies: 3
    Last Post: 07-03-2013, 10:38 AM
  5. Replies: 1
    Last Post: 10-30-2012, 10:29 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