Results 1 to 2 of 2
  1. #1
    aggl is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    1

    Unhappy Cascading listboxes not updating correctly


    Hi everyone! I am working on a very simple DB. The two fields in question are Country and City, both as text. The idea is that the user can choose one country from a single-selection ListBox and after selecting one country the Cities multi-selection ListBox gets populated through the following SQL search. The Table Country_City contains two rows with countries and cities, nothing complicated.

    Code:
    Private Sub BU_AfterUpdate()
        'I deselect all the selected items
        '*** WHY THE IS THIS NOT WORKING ???!!! ***
        For i = 0 To AppliesTo.ListCount - 1
            AppliesTo.Selected(i) = False
        Next i
        City.RowSource = "SELECT Country_City.City " & _
            "FROM Country_City " & _
            "WHERE Country_City.Country = '" & ListBoxCountry.Value & "';"
    After I click/select a country on the first ListBox, the second does get populated correctly. The problem I am having is if the user changes the country, then the previously selected city/cities still stay selected. I tried to reverse that by deselecting all the cities each time I change the country, but the for-next loop does not seem to be doing the job. The funny thing is that if I paste those three lines on a buttom and click it right before selecting another country, it does work.

    Example:
    1) I select "France" on the first ListBox.
    2) I select "Paris" and "Lyon" on the second ListBox.
    3) Now I select "Germany" in the first ListBox.
    4) The second ListBox gets filled by all the cities in Germany, but the ones I selected before (Lyon and Paris) appear on it too, selected.

    Any ideas on how to come around this? I want to reset the selection on the second ListBox in case the user selects another country on the first ListBox.

    Some information on the fields:
    Country: Display Control=ListBox, Row Source Type=Value List, Row Source="France", "Germany"
    City: Display Control=ListBox, Row Source=Table/Query, Row Source=(empty, updates with AfterUpdate event on Country ListBox)

    Thanks a lot in advance for your help!

    Greetings, Agustín

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    What is "AppliesTo"?

    Shouldn't "AppliesTo" be "City" or "Country" list box name. Shouldn't you clear both list.

    If that does not work, can you post your db?

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

Similar Threads

  1. Replies: 15
    Last Post: 12-10-2012, 06:37 PM
  2. Replies: 5
    Last Post: 11-21-2011, 09:59 PM
  3. Table Not Updating Correctly
    By wildthingcg in forum Database Design
    Replies: 8
    Last Post: 09-15-2011, 04:34 PM
  4. Replies: 1
    Last Post: 09-08-2011, 06:59 AM
  5. Cascading combo box updating text box?
    By RemonKoybito in forum Forms
    Replies: 1
    Last Post: 06-16-2011, 10:51 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