Link to home
Start Free TrialLog in
Avatar of Juan Velasquez
Juan VelasquezFlag for United States of America

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.  
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Since you did not post any details on the design of this system or what the rowsources are...
...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
Avatar of Juan Velasquez

ASKER

Thanks that did it
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