Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • 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
chtullu135
Asked:
chtullu135
  • 3
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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
 
chtullu135Author Commented:
Thanks that did it
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Interesting ....
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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