Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sending items from one listbox to another

Posted on 2006-07-12
7
Medium Priority
?
209 Views
Last Modified: 2012-05-05
Hello,

I was wondering if it's possible to get selected items from one list box and select the same items in another listbox?
0
Comment
Question by:Yury Merezhkov
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Expert Comment

by:justchat_1
ID: 17096453
Loop throught each item in the first listbox and if it is selected...select the same item in the second listbox
0
 
LVL 7

Author Comment

by:Yury Merezhkov
ID: 17096472
Thank you, i understand that. But i've just started programming in vb and access :( Sample code would be greatly appreciated.
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17096831
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:jomacinc
ID: 17096873
Here is example code for what RealSnaD is talking about.

Presuming both lists have the same content in the same order:
---------------------------------------------------
Dim lCnt As Long

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

    ' if item is selected, select same in list two
    If List1.Selected(lCnt) Then List2.Selected(lCnt) = True
Next lCnt
---------------------------------------------------
If lists are not same and you want to select item with same text:
---------------------------------------------------
Dim lCnt  As Long
Dim lCnt2 As Long
Dim sTxt  As String

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

    ' check each list two item for same text
    If List1.Selected(lCnt) Then
        sTxt = List1.List(lCnt)

        For lCnt2 = 0 To List2.ListCount - 1

            ' if item has same text as list one item, select it
            If List1.List(lCnt) = sTxt Then List2.Selected(lCnt) = True
            Exit For
        Next lCnt
    End If
Next lCnt

0
 
LVL 4

Accepted Solution

by:
jomacinc earned 500 total points
ID: 17096883
--Correction--
---------------------------------------------------
If lists are not same and you want to select item with same text:
---------------------------------------------------
Dim lCnt  As Long
Dim lCnt2 As Long
Dim sTxt  As String

' loop through each item in list one
For lCnt = 0 To List1.ListCount - 1

    ' check each list two item for same text
    If List1.Selected(lCnt) Then
        sTxt = List1.List(lCnt)

        For lCnt2 = 0 To List2.ListCount - 1

            ' if item has same text as list one item, select it
            If List1.List(lCnt) = sTxt Then List2.Selected(lCnt) = True
            Exit For
        Next lCnt2
    End If
Next lCnt
0
 
LVL 7

Author Comment

by:Yury Merezhkov
ID: 17100193
Here is my code, and it's not working:

    For lCnt = 0 To Me.ClientByDate.ListCount - 1
       If Me.ClientByDate.Selected(lCnt) Then
            sTxt = Me.ClientByDate.ItemData(lCnt)
            For lCnt2 = 0 To Forms!frmFullReport!Client_List.ListCount - 1
                If Forms!frmFullReport!Client_List.ItemData(lCnt2) = sTxt Then
                    Forms!frmFullReport!Client_List.Selected(lCnt2) = True
                End If
            Next lCnt2
        End If
    Next lCnt

Any ideas y?

P.S.: List1.List(lCnt) was giving me an error, that's y i used List1.ItemData(lCnt)
0
 
LVL 7

Author Comment

by:Yury Merezhkov
ID: 17100253
Nevermind, I figured it out. Thanks.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question