How to get cascading combo boxes to work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ncsthbell
    New Member
    • May 2007
    • 167

    #1

    How to get cascading combo boxes to work

    I have 2 combo boxes: 'Division' and 'location'. I want to select a 'division' and have the locations associated with that division be the rowsource for the 'location' combo box (limit the list).
    This is for same table source data, table "DivLoc", columns: are DivLocID, Division, Location

    Division combo box: cmbDivsion
    I have the property for record source set as a query. This query gives the distinct values for divison. This combo box lists the correct results.

    Location combo box: cmbLocation
    On the 'after update' event of cmbDivision, I have put in the following code:
    cmbLocations.Ro wSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = '" & cmbDivisions.va lue & "' order by DL.Location"
    I do not get any values returned in the locations combo box. However, I can run the select statement alone and I get values. I can not figure out what I am doing wrong to prevent the locations values from being displayed as the rowsource.
    Any suggestions would be appreciate. I have look at several posts on this forum and it looks like I have followed the same method.
  • Mariostg
    Contributor
    • Sep 2010
    • 332

    #2
    It could be a problem related to the Column Count or Column width properties of the combo box.
    Last edited by Mariostg; Sep 22 '10, 05:49 PM. Reason: Typo.

    Comment

    • gnawoncents
      New Member
      • May 2010
      • 214

      #3
      Something else you could try is modifying the after update or on change to simply

      Code:
      cmbLocation.Requery
      and put the following code in your row source for cmbLocation

      Code:
      SELECT DISTINCT DivLoc.Location FROM DivLoc WHERE (((DivLoc.Division) Like [cmbDivision]));

      Comment

      • OldBirdman
        Contributor
        • Mar 2007
        • 675

        #4
        Have you tried to see what works in the RowSource?
        For example, your RowSource is:
        Code:
        cmbLocations.RowSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = '" & cmbDivisions.value & "' order by DL.Location"
        Try(1) replace 'V3' with a valid division:
        Code:
        cmbLocations.RowSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = 'V3' order by DL.Location"
        Try(2):
        Code:
        cmbLocations.RowSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = '" & "V3" & "' order by DL.Location"
        Try(3):
        Code:
        cmbLocations.RowSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = '" & [cmbDivisions] & "' order by DL.Location"
        All this assumes your DefaultView is 'Single Form' and not 'Continuous Forms'

        Comment

        • ncsthbell
          New Member
          • May 2007
          • 167

          #5
          I have tried your above suggestion and I still do not get any results in my cmbLocation box. Here are the properties on my combo boxes:

          cmbDivision (same for cmbLocation)
          bound column 1
          column count 1
          column width 1"

          I have tried deleting them and rebuilding again on my form and still have no luck.

          Comment

          • Mariostg
            Contributor
            • Sep 2010
            • 332

            #6
            Weird.
            And I am sure you did a debug.print on your query:
            Code:
            cmbLocations.RowSource = "SELECT DL.[Location] FROM DivLoc DL WHERE DL.Division = '" & cmbDivisions.value & "' order by DL.Location"
            And that is how you confirmed you don't have an empty return by executing it after...

            Comment

            • ncsthbell
              New Member
              • May 2007
              • 167

              #7
              Thanks for everyone's suggestions. I tried everything suggested and still could not get it to work. SO... I created a new form with new combo boxes and this time they work. I may have messed up an option or setting that I was not aware of. But they are working like a charm now! THANKS!!

              Comment

              Working...