Results 1 to 9 of 9
  1. #1
    lynda hunt
    Guest

    List boxes (VBA)

    I need to create a dialog box with 2 list boxes on it. When an item is selected in the first list box I want it to then highlight the corresponding item in the 2nd list box.

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: List boxes (VBA)

    Hope the following will help :

    Private Sub ListBox1_Change()
    ListBox2.ListIndex = ListBox1.ListIndex
    End Sub

    Just copy and paste that code to your form.

    Andrew C

  3. #3
    lynda hunt
    Guest

    Re: List boxes (VBA)

    Yes that has worked thank you.

    The only problem is the although in list box 1 you select which option you require, the corresponding item in the second list box may not be on the same line, it could be 3 or 4 lines lower. Any way to do this?

  4. #4
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: List boxes (VBA)

    That would depend on the relationship between the two lists. Could you be more specific as to how the two lists correspond.

    Andrew C

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List boxes (VBA)

    If you can give us a rule that says when I click on line n in listbox 1 what line should be selected in listbox 2, then yes it can be done.
    Legare Coleman

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: List boxes (VBA)

    If the relationship between the list boxes is 1 for 1 then you may find it easier to use one list box with multiple columns. Then the selection will only be in one place.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    lynda hunt
    Guest

    Re: List boxes (VBA)

    Basically what I need to do is this

    In List Box 1 are the following:

    Appendices Index
    Appendices Title
    Bulleted List

    In the second list box they are as follows:

    Table of Figures
    a-appendix title
    A-List Bullet

    These are styles that are applicable to all documents created.

    The first list box contains styles that were used in Word 95, the second list box contains styles that are to be used now in Word 2000.

    What needs to happen is when someone selects a style in the first box for example

    appendices Index it should then select the new style in box 2 which would be Table of Figures.

    Hope this makes sense

  8. #8
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List boxes (VBA)

    Lynda,

    My apologies.

    I think I can understand what you're saying- but that does not make sense in comparison with your first reply.

    I thought from this post that you are saying, "If I select Bulleted List" from ListBox1, then select A-List Bullet from ListBox2."

    But I don't understand why, from the earlier post
    <hr>The only problem is the although in list box 1 you select which option you require, the corresponding item in the second list box may not be on the same line, it could be 3 or 4 lines lower. Any way to do this?
    <hr>
    Are you saying that if one option is selectd from listbox1, then it's possible there's more than one option selected from listbox2?

    Is it worth populating listbox2 only when one option from Listbox1 is clicked? Or should every style be available regardless of Listbox1?

    Sorry to raise so many questions- but I'm still not quite clear on you requirements.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  9. #9
    Star Lounger
    Join Date
    Jan 2001
    Location
    L.A., California
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: List boxes (VBA)

    Why not write a simple loop to check for the active item in listbox 1 within listbox 2? For example:

    <pre>
    Dim lLoop as Long
    Dim lFoundIdx as Long
    Dim sText as String

    sText = ListBox1.List
    lFoundIdx = -1
    lLoop = 0

    Do While lLoop < ListBox2.ListCount
    If ListBox2.List(lLoop) = sText Then
    lFoundIdx = lLoop
    Exit Do
    End If
    lLoop = lLoop + 1
    Loop

    If lFoundIdx <> -1 Then
    ListBox2.Listindex = lFoundIdx
    End If

    </pre>


Posting Permissions

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