Listbox Issue. Scroll two listboxes at same time.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SandeepJagdeva
    New Member
    • Jan 2007
    • 23

    #1

    Listbox Issue. Scroll two listboxes at same time.

    Hi to all
    I have two listbox with lots of items in it. I want to do is, when user scroll one listbox then second listbox automatically scroll according to first. Someone knows how to do this. I search the web but didn’t get what I really need. Help Me!
    Thanx in Advance
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    You need an event that occurs when the listbox scrolls.
    You also need a read/write property that identifies the index of the item at the top of the list in view.
    As far as I can see, in access, neither of these exist for the list box.

    Maybe it's time to rethink what you are doing?
    I can't imagine the scenario where you would need to do that
    which wouldn't be better achieved some other way.


    Microsoft does have an example of doing this
    but it is done in visual basic...not VBA

    google this
    How to Program Two List Boxes to Scroll Together

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I'd really like to know the point of this requirement. Like Delerna, I can't imagine the scenario where you would need to do that which wouldn't be better achieved some other way.

      Linq ;0)>

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by SandeepJagdeva
        Hi to all
        I have two listbox with lots of items in it. I want to do is, when user scroll one listbox then second listbox automatically scroll according to first. Someone knows how to do this. I search the web but didn’t get what I really need. Help Me!
        Thanx in Advance
        In the absolute simplest of cases where both List Boxes contain the same number of entries, the 1st List Box is named List1, and the 2nd List Box is named List2, the following code, when placed in the AfterUpdate() Event of List 1, will keep the scrolled items of List 2 in sync with List 1 when using the UP and DOWN Arrow Keys:
        Code:
        Private Sub List1_AfterUpdate()
        Dim L1 As ListBox
        Dim L2 As ListBox
        
        Set L1 = Me![List1]
        Set L2 = Me![List2]
        
        L2.Selected(L1.ListIndex) = True
        End Sub
        P.S. - I will not get more complicated than this since, like linq and Delerna, I would like to know also what you are trying to accomplish.

        Comment

        • SandeepJagdeva
          New Member
          • Jan 2007
          • 23

          #5
          First of all Thanx to all for give me some good idias.
          I gave u some detail why I need to scroll both listbox at same time. I have a form that prints Daily billing of a ‘Departmen tal Store’. I add two listbox name “lst_SrNo” is single column and “lstProduct_det ail” with 5 column, one is for Serial No and second is for Product detail , a combobox, and some textbox for complete the task. Now user selects a product code from combobox that is connected to a table named ‘product_detail ’ and detail of selected code will be loaded to lstProduct_deta il, and in the lst_SrNo a number is added to it. As user select product code, then first listbox add a number like lstNumber=lstNu mber+1. Product detail adds to Second listbox. Its ok till now, if user add more then 16 items in listbox then both list box need to scroll down, if user scroll “lstProduct_det ail” listbox then its corresponding Serial No. does’t match. is it clear

          Why I need two list box?
          Ans is in my previous post :

          Comment

          • SandeepJagdeva
            New Member
            • Jan 2007
            • 23

            #6
            Originally posted by ADezii
            In the absolute simplest of cases where both List Boxes contain the same number of entries, the 1st List Box is named List1, and the 2nd List Box is named List2, the following code, when placed in the AfterUpdate() Event of List 1, will keep the scrolled items of List 2 in sync with List 1 when using the UP and DOWN Arrow Keys:
            Code:
            Private Sub List1_AfterUpdate()
            Dim L1 As ListBox
            Dim L2 As ListBox
            
            Set L1 = Me![List1]
            Set L2 = Me![List2]
            
            L2.Selected(L1.ListIndex) = True
            End Sub
            P.S. - I will not get more complicated than this since, like linq and Delerna, I would like to know also what you are trying to accomplish.
            Thanx man
            This is what i need. This will sloved my problem, is any way, that this will wrok with mouse as with key up-down, when user click on scroll button of listbox?

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by SandeepJagdeva
              Thanx man
              This is what i need. This will sloved my problem, is any way, that this will wrok with mouse as with key up-down, when user click on scroll button of listbox?
              To the best of my knowledge, this simply cannot be done.

              Comment

              Working...