Show all records through combo box and command button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WiscCard
    New Member
    • Mar 2008
    • 6

    Show all records through combo box and command button

    This seems simple enough, but I am having problems.
    I have a table of customer information. I have a form with various combo boxes displaying unique customer information (in this case, zone and broker, but I'll add others before it is done.
    I want each user to choose what they want out of the combo boxes, then hit the command button, which will display the results on a customized form. If they choose both combo boxes, it works gerat.
    The problem I am having that if the user just chooses zone, but nothing in broker, it display no results. I thought adding an " All" to each would cure that, but it has not, but I don't think I am doing it correctly.

    I'll show exactly what I have so far. For the Broker Combo Box I have as my row source:
    Code:
    SELECT BROKER As Filter, BROKER FROM CUSTOMERS UNION SELECT "*" As Filter ," All" As BROKER FROM CUSTOMERS ORDER BY BROKER;
    My column count is 2, column width is 0", 2".

    This brings an option in my combo box with the name All, but if you choose that and hit the command button, no results are displayed.

    The code I have in the command button is:
    Code:
    Private Sub Command5_Click()
    DoCmd.OpenForm "ALLCUSTOMERSFORM", , , "[BROKER] = '" & Me![Combo1].Column(0) & "' AND [ZONE] = '" & Me![Combo2].Column(0) & "'"
    
    End Sub
    Now I think my problem is that all I have done is add the All option to the combo box, but I need something else to tell it to actually show all.
    Maybe something in the After Update section, but I don't know what!

    Please help!!!

    Thank you!
    Last edited by JKing; Mar 3 '08, 06:03 PM. Reason: [CODE] Tags
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    If you're only going to use "All" in ONE combo box, then this should work:

    Code:
    Private Sub Command5_Click()
    if me.combo2.value = "All" or isnull(me.combo2.value) then
         DoCmd.OpenForm "ALLCUSTOMERSFORM", , , "[BROKER] <> '" & Me![Combo1].value & "' AND [ZONE] = '" & Me![Combo2].value & "'"
    else
          DoCmd.OpenForm "ALLCUSTOMERSFORM", , , "[BROKER] = '" & Me![Combo1].value & "' AND [ZONE] = '" & Me![Combo2].value & "'"
    End Sub
    So basically if the value is "All" or is nothing, then it will return any values that do not match "All" or nothing. Otherwise, it should filter off whatever broker is selected.

    Comment

    • WiscCard
      New Member
      • Mar 2008
      • 6

      #3
      Originally posted by Megalog
      If you're only going to use "All" in ONE combo box, then this should work:

      Code:
      Private Sub Command5_Click()
      if me.combo2.value = "All" or isnull(me.combo2.value) then
           DoCmd.OpenForm "ALLCUSTOMERSFORM", , , "[BROKER] <> '" & Me![Combo1].value & "' AND [ZONE] = '" & Me![Combo2].value & "'"
      else
            DoCmd.OpenForm "ALLCUSTOMERSFORM", , , "[BROKER] = '" & Me![Combo1].value & "' AND [ZONE] = '" & Me![Combo2].value & "'"
      End Sub
      So basically if the value is "All" or is nothing, then it will return any values that do not match "All" or nothing. Otherwise, it should filter off whatever broker is selected.
      Thank you, but I would prefer if All were a part of each combo box.
      For example: If someone just wanted to see all East customers, they would selecte East as Zone and All as broker.

      Any suggestions?

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Here's an article that you may wish to read. It's fairly well written and has links to examples you can download.

        Adding "All" option to a combobox

        Comment

        Working...