Juan Velasquez
asked on
Additional items appearing in list box
Hello,
I am trying to populate a list box with selections made in another list box. However, when I execute the code below, the number one appears at the top of the list in addition to all the other selections. For example, if I select Apple from the source listbox, the number 1 is listed above the Apple entry in the destination list box.
I am trying to populate a list box with selections made in another list box. However, when I execute the code below, the number one appears at the top of the list in addition to all the other selections. For example, if I select Apple from the source listbox, the number 1 is listed above the Apple entry in the destination list box.
Private Sub cmdSelectIndividual_Click()
Dim varSelectedItem As Variant
Dim x As Integer
Me.lstDestinationFields.RowSource = vbNull
If Me.lstSourceFields.ItemsSelected.Count > 0 Then
For x = 0 To Me.lstSourceFields.ListCount - 1
If Me.lstSourceFields.Selected(x) Then
Me.lstDestinationFields.AddItem Me.lstSourceFields.ItemData(x)
End If
Next
Me.lstDestinationFields.Requery
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks that did it
Interesting ....
Capture1.gif
Capture1.gif
From Help:
VarType Constants
The following constants can be used anywhere in your code in place of the actual values:
Constant Value Description
vbEmpty 0 Uninitialized (default)
vbNull 1 Contains no valid data
Pretty clear now what happened. Setting RowSource to vbNull essentially added one item ... a '1' ... and then the AddItem method added the remaining items.
Who would have thought ...
mx
VarType Constants
The following constants can be used anywhere in your code in place of the actual values:
Constant Value Description
vbEmpty 0 Uninitialized (default)
vbNull 1 Contains no valid data
Pretty clear now what happened. Setting RowSource to vbNull essentially added one item ... a '1' ... and then the AddItem method added the remaining items.
Who would have thought ...
mx
...All I can do is post a sample of how I do this...
http://filedb.experts-exchange.com/incoming/2009/02_w06/103068/Access-Basic-SampleMoveSelectedI.mdb
JeffCoachman