Solved

Sending items from one listbox to another

Posted on 2006-07-12
7
204 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

770 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