PC Review


Reply
Thread Tools Rate Thread

Capturing Listbox Selections

 
 
Randy
Guest
Posts: n/a
 
      14th Sep 2007
Hi,
I've got two multi-select listboxes on a userform. The idea is that
listbox A contains all possible items and listbox B is a subset of A
defined by the user. I'm struggling with capturing the selected
values in A so that they can be copied to B. Here is my code:

With frmManageGroups.lbxA
For x = 0 To .ListCount - 1
If .Selected(x) = True Then
frmManageGroups.lbxB.AddItem .List(.ListIndex)
.Selected(x) = False
End If
Next
End With

The way that this is written, it only copies the last item selected in
listbox A. For example, if the listbox A contains the letters A,B,
and C as its items and the user selects A and C, my code copies the
letter C twice to listbox B instead of the letters A and C.

Can anybody help?
Thanks,
Randy

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      14th Sep 2007
Not usre what you were really tryiing to do. this is how I prevent
duplicates from getting into a Listbox. I checd the with statement from A to
b. I'm checking to see if the item is already in the list box B

With frmManageGroups.lbxB
For x = 0 To .ListCount - 1
Found = False
If frmManageGroups.lbxB = .List(x) Then

Found = True
exit for
End If
Next
if found = False then
frmManageGroups.lbxB.AddItem
end if
End With


"Randy" wrote:

> Hi,
> I've got two multi-select listboxes on a userform. The idea is that
> listbox A contains all possible items and listbox B is a subset of A
> defined by the user. I'm struggling with capturing the selected
> values in A so that they can be copied to B. Here is my code:
>
> With frmManageGroups.lbxA
> For x = 0 To .ListCount - 1
> If .Selected(x) = True Then
> frmManageGroups.lbxB.AddItem .List(.ListIndex)
> .Selected(x) = False
> End If
> Next
> End With
>
> The way that this is written, it only copies the last item selected in
> listbox A. For example, if the listbox A contains the letters A,B,
> and C as its items and the user selects A and C, my code copies the
> letter C twice to listbox B instead of the letters A and C.
>
> Can anybody help?
> Thanks,
> Randy
>
>

 
Reply With Quote
 
George Nicholson
Guest
Posts: n/a
 
      14th Sep 2007
>frmManageGroups.lbxB.AddItem .List(.ListIndex)

You don't want to use ListIndex there. In a multi-select list box,
ListIndex is the item that has the *focus* in the UI, so if 2 items have
been selected, but C has the focus (whether selected or not!), you'll end up
with 2 C's.

frmManageGroups.lbxB.AddItem .List(x)


HTH,


"Randy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I've got two multi-select listboxes on a userform. The idea is that
> listbox A contains all possible items and listbox B is a subset of A
> defined by the user. I'm struggling with capturing the selected
> values in A so that they can be copied to B. Here is my code:
>
> With frmManageGroups.lbxA
> For x = 0 To .ListCount - 1
> If .Selected(x) = True Then
> frmManageGroups.lbxB.AddItem .List(.ListIndex)
> .Selected(x) = False
> End If
> Next
> End With
>
> The way that this is written, it only copies the last item selected in
> listbox A. For example, if the listbox A contains the letters A,B,
> and C as its items and the user selects A and C, my code copies the
> letter C twice to listbox B instead of the letters A and C.
>
> Can anybody help?
> Thanks,
> Randy
>



 
Reply With Quote
 
Randy
Guest
Posts: n/a
 
      14th Sep 2007
You're right, George. I just needed (x) and not (.ListIndex).

Thanks to both of you for your advice.

Randy

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
first listbox populates second listbox and allows multiple selections Repent Microsoft Access Forms 1 16th Aug 2009 09:14 PM
Re: 1st listbox populates 2nd listbox, allows multi selections Piet Linden Microsoft Access Forms 0 12th Jun 2009 04:29 AM
Re: 1st listbox populates 2nd listbox, allows multi selections Jeff Boyce Microsoft Access Forms 0 12th Jun 2009 12:19 AM
listbox selections dennis.mccarthy@us.atlascopco.com Microsoft Excel Programming 1 24th Feb 2009 02:57 AM
Re: Listbox multiple selections? Cheryl Fischer Microsoft Access 1 16th Mar 2004 08:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:08 PM.