Results 1 to 11 of 11
  1. #1
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22

    Cascading combo

    I have a table with lists of Provinces (22 ) Districts (89) - each province have more than 1 district.

    I have 2 combo box (Province first and District second).
    I want the District combo to show only the list of districts that are in province selected in first combo. Below is my simple code: but it is not working.

    Private Sub cboProvince_AfterUpdate()


    Dim strSource As String
    strSource = "SELECT Districts " & _
    "FROM All " & _
    "WHERE Provinces = '" & Me.cboProvince & "' ORDER BY Districts"
    End Sub

    PLEASE HELP
    Click image for larger version. 

Name:	Capture.PNG 
Views:	22 
Size:	31.2 KB 
ID:	38253

  2. #2
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You are not setting the next combo to the source string you are setting up. Assuming your other combo is called cmbDistricts something like;
    Code:
    Private Sub cboProvince_AfterUpdate()
        Dim strSource As String
        strSource = "SELECT Districts " & _
        "FROM All " & _
        "WHERE Provinces = '" & Me.cboProvince & "' ORDER BY Districts"
        
       me.cmbDistricts.rowsource = strSource
    
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi

    From your screenshot it looks like you have both Provinces and Districts in the same table?

    I would suggest you need 1 Table for the Provinces and then a 2nd table to list all District associations.

    You can then use Cascading Combobox's as they are designed to be used.

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It is OK to have the Province and District in the same table.

    1) The row source for the combo box "cboProvince" would be
    Code:
    SELECT DISTINCT Province FROM All ORDER BY Province

    2) The row source for the combo box "cboDistrict" would be
    Code:
    SELECT Districts FROM All WHERE Provinces = '" & Forms!YourFormName.cboProvince & "' ORDER BY Districts
    (Change YourFormName"" to your form name)


    3) Then you would need to add code in the after update event of "cboProvince"
    Code:
    Private Sub cboProvince_AfterUpdate()
        Me.cboDistrict.Requery
    End Sub

    I prefer this method rather than always changing the combo box row source.
    Last edited by ssanfu; 05-01-2019 at 10:49 PM.

  5. #5
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22
    When I try the form, it says synthax error from FROM clause.

    I dont know, please tip mr

  6. #6
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22
    Hi sir
    I tried in but it says, synthax error from FROM clause

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I don't know your table names nor the field names or control names.

    It would be helpful if you would post your dB...

  8. #8
    byulogia@gmail.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2019
    Location
    Papua New Guinea
    Posts
    22
    Quote Originally Posted by ssanfu View Post
    I don't know your table names nor the field names or control names.

    It would be helpful if you would post your dB...

    Table Name ALL
    Field Names (Province , Districts)

  9. #9
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Oops, I had a brain freeze. The reference to the combo box "cboProvince"was wrong


    The row source for the combo box "cboDistrict" would be
    Code:
    SELECT Districts FROM All WHERE Provinces = '" & Forms!YourFormName.cboProvince & "' ORDER BY Districts
    Change "YourFormName" to the name of your form.


    If your form name is "Form2", you would use "Forms!Form2.cboProvince"
    If your form name is "frmProvinceDistrict", you would use "Forms!frmProvinceDistrict.cboProvince"




    I edited my previous post to correct my eerror...


    (The attached dB is my example of cascading combo boxes)
    Attached Files Attached Files

  10. #10
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi Steve

    Can you tell me which unique ID you would be saving using this method?

  11. #11
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by mike60smart View Post
    Can you tell me which unique ID you would be saving using this method?
    Not saving an unique ID. Saving the text selection in the combo box to a text field.

    In this case, looking at the code in the OP's first post, it appears that the Province and District combo boxes are saving the respective selected text names.
    Not sure what the table design looks like. So I answered the OP's question based on my perception of the table design.



    Would I save the actual text? No, I design my tables to have an autonumber PK field and a numeric linking FK fields. And thus would need two table as indicated in your posts.

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

Similar Threads

  1. Self-Cascading Combo Box
    By WCStarks in forum Access
    Replies: 2
    Last Post: 01-18-2018, 01:11 PM
  2. Cascading Combo - HELP!!!
    By ajh2014 in forum Forms
    Replies: 5
    Last Post: 10-17-2014, 06:20 AM
  3. Replies: 1
    Last Post: 02-27-2014, 03:43 PM
  4. Cascading combo box
    By Plix in forum Access
    Replies: 1
    Last Post: 02-20-2013, 06:54 AM
  5. cascading combo
    By rexb in forum Forms
    Replies: 9
    Last Post: 10-26-2009, 04:10 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