Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2004
    Posts
    364

    Unanswered: Dependent Listboxes question

    Hello,

    I was wondering how to fix the following problem..

    I have 3 listboxes on a form, lst1, lst2, lst3.

    When a row is selected from lst1, related records for lst1 are shown in lst2.

    Then, when a row is then selected from lst2, related records for lst2 are shown in lst3.

    This is fine.

    But, when I select a new row in lst1, lst2 shows related records, but lst3 still shows the records from the last selection - until lst2 is selected.

    How can I make lst3 clear its contents when I click on lst1? I have tried using lst1's onlclick event and me.lst3.rowsource = "" but the rowsource then always remains empty.

    Any ideas?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Call the AfterUpdate event handler of the second form when you change its rowset. Changes done by code do not trigger the BeforeUpdate and AfterUpdate event.
    Have a nice day!

  3. #3
    Join Date
    Aug 2004
    Posts
    364
    I only have one form - with 3 listboxes.

    Im not changing the rowset of lst2, I just want lst3 to go blank when I select a new row in lst1.
    Last edited by moss2076; 09-26-11 at 18:42.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Read: "Second ListBox", sorry!

    Im not changing the rowset of lst2
    Yes you are. You wrote:
    when I select a new row in lst1, lst2 shows related records
    This means that the contents (the rowset) of lst2 is changed according to the selection in lst1.
    Have a nice day!

  5. #5
    Join Date
    Aug 2004
    Posts
    364
    You are right I am! Still no nearer to working it out though..

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    What's the code in lst2_AfterUpdate() (or BeforeUpdate)?
    Have a nice day!

  7. #7
    Join Date
    Aug 2004
    Posts
    364
    Currently, there isn't. The row source of each list box is set in the properties box and an SQL query with a reference to the previous list box. I'm not at my PC right now so can't explain more precisely.

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Try:
    Code:
    Private Sub lst1_AfterUpdate()
        Me.lst2.Requery
        Me.lst3.Requery
    End Sub
    Have a nice day!

  9. #9
    Join Date
    Aug 2004
    Posts
    364
    That was the first thing I tried, and it doesnt update the third listbox when a different row on the first listbox is selected. The second listbox updates when a different row is selected in the first listbox, but not for the third listbox.

  10. #10
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    When List2 is requeried, no item in it is selected, but a previous selected item changed the Value property of the list. This value is not affected by the Requery method. You can manually reset it:
    Code:
    Private Sub List0_AfterUpdate()
    
        Me.List2.Requery
        Me.List2.Value = Nothing
        Me.List3.Requery
        
    End Sub
    
    Private Sub List2_AfterUpdate()
    
        Me.List3.Requery
        
    End Sub
    Have a nice day!

  11. #11
    Join Date
    Aug 2004
    Posts
    364
    I think that code has sorted it, but changed Me.List2.Value = Nothing to Me.List2.Value = Null.

    I had also tried me.list2.value = vbnullstring but that didnt work, but Me.List2.Value = Null is working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •