Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending items from one listbox to another

Posted on 2006-07-12
7
Medium Priority
?
210 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
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

972 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