Results 1 to 8 of 8
  1. #1
    jrichardson10 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    16

    How to Filter County Options in a ComboBox Based on State

    So I have a table with my options for state, and a second table with all the county options, sorted by state. On a third form where both pieces of data are recorded, how do I filter what county options are available based upon the state I have selected?



    This will ultimately pull over to the form I have also, but I figured this was the best place to start. Thanks!

  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
    jrichardson10 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    16
    Paul,

    That seems to be what I want to accomplish, but I'm not particularly well-versed in coding. I do everything the dummy way. How would I accomplish this without the coding part? The theory looks perfect, I'm just not great at the application part.

  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
    Well, I gave you the code. The least code is the first, where the second combo's source refers to the first and you just requery it. You could do that with a macro if you prefer.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jrichardson10 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    16
    Paul,

    You did, thank you. I tried the code you provided, both of them even. I altered the names to reflect my database's naming system but I'm not seeing the same result. I've attached the database as we were just working on it so you can see that I'm not having much luck. I've saved and reopened but nothing has changed. If it's an obvious fix I apologize but both my coworker and I are lost.
    Attached Files Attached Files

  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,521
    I don't see an attempt at cascading combos anywhere. There's no code behind the state combo on the parent form. You'd need to make sure you compared the numeric state value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jrichardson10 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2017
    Posts
    16
    Well that may be partially because I (wrongly) put it on the FKCounties instead of States. Brilliant. I moved it to no avail.

    I checked and changed my variables to all number variables. I included the code this time, but I promise it's there, though maybe not where it's supposed to be... Sorry I'm kind of terrible at this. I'm self taught over the last few years and because I use access once every 5 or 6 months, I haven't learned or retained enough to be well-versed.

    Option Compare Database
    Option Explicit
    Private Sub cboFKStates_AfterUpdate()
    Me.cboFKCounties = vbNullString
    Me.cboFKCounties.Requery
    End Sub
    Private Sub cboFKStates_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT ID_County " & _
    "FROM tblCounties " & _
    "WHERE FKState = '" & Me.cboFKStates & "' ORDER BY FKCounties"
    Me.cboFKCounties.RowSource = strSource
    Me.cboFKCounties = vbNullString
    End Sub

  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,521
    Ah, you must have changed the name of the combo. The code is not associated, and the name of the combo is just "FK_States". This appears to work:

    Code:
      Dim strSource     As String
    
      strSource = "SELECT ID_County, var_CountyName " & _
                  "FROM tblCounties " & _
                  "WHERE FKState = " & Me.FK_States
      Me.FK_Counties.RowSource = strSource
      Me.FK_Counties = vbNullString
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Filter Query combobox options
    By dhannant in forum Access
    Replies: 2
    Last Post: 05-12-2015, 03:25 AM
  2. Filter combobox options
    By Voodeux2014 in forum Forms
    Replies: 1
    Last Post: 03-17-2015, 10:57 AM
  3. Replies: 1
    Last Post: 09-06-2011, 01:47 PM
  4. Normalizing various City/County/State combinations (w/out zip)
    By DorkyDuvessa in forum Database Design
    Replies: 2
    Last Post: 05-08-2011, 07:49 PM
  5. Replies: 0
    Last Post: 08-24-2010, 06:38 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