Solved

Sending items from one listbox to another

Posted on 2006-07-12
7
202 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:RealSnaD
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:RealSnaD
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 125 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:RealSnaD
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:RealSnaD
ID: 17100253
Nevermind, I figured it out. Thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now