Results 1 to 8 of 8
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Trying To Join 2 Combos

    I have 2 combo boxes on a form
    cboWkLoc This selects workers city where employed This combo gets data from company table
    CboEmp This Selects Employee

    I am trying to join these both combos so when I select City (e.g Reno ) its shows only employees working in Reno - This combo gets data from Purchases table

    I have tried to work on the following code but could not figure it out.






    Private Sub cboWkLoc_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT City " & _
    "FROM Purchase " & _
    "WHERE Employee = '" & Me.cboWkLoc & "' ORDER BY City"
    Me.cboEmp.RowSource = strSource
    Me.cboEmp = vbNullString
    End Sub

  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,522
    Looks like you have your fields mixed up. You're comparing employee to city.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    are there any examples available so I can see how its done

  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,522
    Sure:

    http://www.baldyweb.com/CascadingCombo.htm

    but I think your method is fine, it's the logic of what fields you have where in your SQL that looks off.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I was using this example, but both combo boxes are using the same table
    whereas I want to use 2 different tables
    combo: cboWkLoc uses table: COMPANY (City is Selected) Field: EmployeeWorkLoc
    Combo: cboemp uses table: PURCHASES (Employee is Selected) Field: EmployeeName

    I could not figure how to define that in code

  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,522
    My point is that where you say the second combo is to select an employee, you have "SELECT City" in the SQL. You say the user selects a city in the first combo, but in the SQL you refer to employee: "WHERE Employee = ..." I would expect those to be reversed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Have done it
    Sample attached

    Used the following code

    Private Sub CboLoc_AfterUpdate()
    Dim strSource As String
    strSource = "SELECT ComapnyName " & _
    "FROM Company " & _
    "WHERE EmployeeWorkLoc = '" & Me.CboLoc & "' ORDER BY ComapnyName"
    Me.CboEmpl.RowSource = strSource
    Me.CboEmpl = vbNullString
    End Sub



    pbaldy Thank you for pointing me in the right direction.
    Attached Files Attached Files

  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,522
    No problem.
    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. Combos and Queries
    By glenn91 in forum Queries
    Replies: 3
    Last Post: 03-19-2013, 10:34 AM
  2. Cascading combos in a form
    By jessaw in forum Forms
    Replies: 1
    Last Post: 11-02-2012, 02:13 AM
  3. Cascading combos issue
    By Andyjones in forum Programming
    Replies: 5
    Last Post: 04-14-2012, 11:09 AM
  4. Combos
    By AdventureBob in forum Forms
    Replies: 1
    Last Post: 01-20-2012, 08:54 AM
  5. Replies: 3
    Last Post: 10-17-2011, 10:36 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