• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

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

0
Juan Velasquez
Asked:
Juan Velasquez
  • 3
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
One thing for sure ... change  this

Me.lstDestinationFields.RowSource = vbNull

to

Me.lstDestinationFields.RowSource = ""

since the RowSource is a String property.

mx
0
 
Jeffrey CoachmanMIS LiasonCommented:
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
0
 
Juan VelasquezAuthor Commented:
Thanks that did it
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Interesting ....
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now