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

Additional items appearing in 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
    End If
End Sub

Open in new window

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

Me.lstDestinationFields.RowSource = vbNull


Me.lstDestinationFields.RowSource = ""

since the RowSource is a String property.

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

Juan VelasquezAuthor Commented:
Thanks that did it
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Interesting ....
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 ...

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