How to get listboxes to display values based on row data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Blackman
    New Member
    • Feb 2011
    • 6

    How to get listboxes to display values based on row data?

    I have a form with 4 unbound listboxes (LB).

    When the form opens, I want:

    1. LB1 to display values in row 1;

    2. LB3 to display data based on the value of LB1;

    3. LB4 to display data based on the value of LB3;

    4. LB2 to select the the row that agrees with row 1 of LB4

    I can get this all to happen AFTER the form is opened, but not at the time of the OnOpen or OnLoad events.

    Any suggestions?
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    If you could perhaps expand upon your application it may help us to understand what is going on.

    You are trying to have cascaded listboxes - is that the idea?

    Perhaps you could post what the sources of the listboxes are, and the VBA code for how you are trying to fill them from the Load or Open events, because I cannot yet understand what it is you really need help on here from what you've posted.

    Does your form itself have a recordsource? If so, please bear in mind that the recordsource may take some time for Access to process to the point where it can display other contents on the form, including your unbound listboxes, but I'm just guessing here.

    -Stewart
    Last edited by Stewart Ross; Feb 6 '11, 09:28 AM. Reason: Realised that this was a cascade question

    Comment

    • David Blackman
      New Member
      • Feb 2011
      • 6

      #3
      Thanks for responding. I finally go it worked out by using the following code in the OnCurrent event:

      Code:
      Dim Ctl(3) As ListBox
          Dim n As Integer
          
          Set Ctl(0) = List_Committee
          Set Ctl(1) = List_CommitteeMember
          Set Ctl(2) = List_SubCommittee
          Set Ctl(3) = List_SubCommitteeMember
          
          Ctl(0) = ComID
          Ctl(2) = ComSubID
          
          With Ctl(3)
              .Requery
              For n = 0 To .ListCount
                  If CLng(.Column(3, n)) = SenateID Then
                      .Selected(n) = True
                  Else
                      .Selected(n) = False
                  End If
              Next n
          End With
          
          With Ctl(1)
              .Requery
              For n = 0 To .ListCount
                  If CLng(.Column(3, n)) = SenateID Then
                      .Selected(n) = True
                  Else
                      .Selected(n) = False
                  End If
              Next n
          End With
          
          Me.Refresh
      Not an elegant solution, but it does work. : )
      Last edited by Stewart Ross; Feb 7 '11, 08:39 PM. Reason: put code tags around code segment

      Comment

      Working...