Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23

    Combo box to filter a combo box

    I'm designing a form with two combo boxes "Country" and "Region"



    I would like for my combo box "Country" to filter out the available options for "Region" based on the selection of the "Country" combo box.

    I know that this is possible. I have seen the code for it. But I cannot seem to apply the code to my own form.

    Any and all help, much appreciated.

    -S

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

  3. #3
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    i'm going to try this code (again) in the morning. but the set up youve shown is different from what I've seen. Mine is currently set up like the second option but it has the requery at the end instead of the vb null. Either way its a little Greek to me. I can't figure out how to write mine to work with yours. Sorry. Any chance you could explain this a little more in detail?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Why don't you post what you're trying and how it fails?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    This is the code I found on http://www.databasedev.co.uk/filter_combo_boxes.html

    I attempted to modify it so that it would work in my situation (replace Store with "Country" and Manager with "Region")

    However I cannot figure out if I need to code all the table fields as is shown in the sample code. If I do its going to be a massive amount of coding bc I have nearly 30 fields of data being returned.

    Thanks for you help and understanding.

    Private Sub cboStore_AfterUpdate()
    Dim sManagerSource As String

    sManagerSource = "SELECT [tblManager].[lngManagerID]," & _
    " [tblManager].[lngStoreID]," & _
    " [tblManager].[strManagerName] " & _
    "FROM tblManager " & _
    "WHERE [lngStoreID] = " & Me.cboStore.Value
    Me.cboManager.RowSource = sManagerSource
    Me.cboManager.Requery
    End Sub

  6. #6
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    Hey,

    I looked at your codes. Downloaded the sample you posted. Tried it on mine. and it doesn't work. My second field doesn't update.

    What am I doing wrong??

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The sample should certainly work. Is the db in a trusted location or have you enabled code?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    Yes. The db is trusted. And your sample works fine. I just can't figure out why my versions of your code is failing.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    Sorry for being out for so long. I finally figured out the reason why I was getting the syntax error and why the second field wasn't updated. Turns out I was referencing a Column Name that didn't exist.

    But now for a second problem. I am having duplicate values returned in my second combo box. But the Row Source is set for "Select Distinct"

    Any ideas? Thanks for all your help Paul.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    DISTINCT operates on all fields in the SELECT clause; perhaps that's what's happening?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    Its possible. But the "Select Distinct" is set as the row source for my second box. It only draws from one column on the table. Should I change how my row source is gathered for the second Combo Box?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    How is it gathered? If there's only one field, the DISTINCT should work.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    svrich is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2014
    Posts
    23
    Well prior to doing the Cascading box the DISTINCT was functioning. I actually had the DISTINCT on box boxes for the Row source and it was working fine.

    And I'm not sure what you're asking about how it's gathered.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What's the code to change its row source?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 10-01-2013, 09:25 PM
  2. Filter Combo box - Help
    By mar_t in forum Forms
    Replies: 3
    Last Post: 01-31-2011, 07:08 AM
  3. filter value in a combo box
    By dada in forum Programming
    Replies: 3
    Last Post: 09-05-2010, 01:22 PM
  4. Combo Box filter – help!
    By catat in forum Forms
    Replies: 1
    Last Post: 08-24-2010, 04:15 PM
  5. Combo Box Filter
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-27-2009, 12:54 PM

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