Results 1 to 4 of 4
  1. #1
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74

    Cascading combobox based on related table

    I'm trying to use cascading comboboxes to filter data. The user will use the boxes to choose a project to run a report.



    I have a combobox (cboState) that queries all the distinct states from a related table. Once the user makes a selection there it should filter the second combobox to only contain projects in that state. In the example below, I've selected Alabama in cboState. This project, however, only covers one state which is Louisiana. How do I need to format my query to return one record if the value of cboState is included in the related State table

    Just to clarify the cascading combobox portion works fine. I have another value (filter by region) which is in the project table as opposed to a related table. When I make a selection in that box, the project combobox is properly filtered.

    Here's the code on for the after update event on cboState
    Code:
    Private Sub cboState_AfterUpdate()
        cboProject.RowSource = "SELECT Project.ProjectID, Project.ProjectTitle, Project.FWSregion, State.State " & _
            "FROM Project, State " & _
            "WHERE  State.State = '" & cboState & "'; "
        cboProject = Null
        
        Debug.Print cboProject.RowSource
    End Sub
    Click image for larger version. 

Name:	cascade.png 
Views:	11 
Size:	18.4 KB 
ID:	12655

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I think you have a table design issue or an sql issue.
    The sql for your row source shows 2 tables, but you have no join. Based on your sample data, I would guess you have 1 project in Alabama, and you are getting repeated data for each Project*State in your table.

    Can you please post a copy of your database (no confidential info) in zip format? Also, highlight an example of what you want to see based on some data and combo selections -- to focus the investigation.

  3. #3
    rhewitt is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    74
    Thanks -- I'd been copying and pasting from some of my other code and forgot to add the join. Everything is working as expected with the following code:

    Code:
    Private Sub cboState_AfterUpdate()
        cboProject.RowSource = "SELECT Project.ProjectID, Project.ProjectTitle, Project.FWSregion, State.State " & _
            "FROM Project INNER JOIN State ON Project.ProjectID = State.ProjectID " & _
            "WHERE  State.State = '" & cboState & "'; "
        cboProject = Null
    End Sub

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Glad you have it sorted out. Thanks for posting the solution.

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

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2012, 03:31 AM
  2. cascading combobox
    By ashu.doc in forum Forms
    Replies: 7
    Last Post: 09-08-2012, 10:39 AM
  3. Replies: 7
    Last Post: 07-02-2012, 10:50 PM
  4. Replies: 4
    Last Post: 04-26-2012, 11:04 AM
  5. Replies: 2
    Last Post: 04-11-2011, 07:33 AM

Tags for this Thread

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