Solved

Sending items from one listbox to another

Posted on 2006-07-12
7
205 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

829 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