listbox selection

groengoen

Registered User.
Local time
Today, 14:45
Joined
Oct 22, 2005
Messages
141
I have looked at the other threads on this but haven't come across exactly the same problem. It is driving me nuts. Here is the code that I am using to select fields in a list box and put them into an unbound textbox:

For x = 0 To lstProcName.ListCount - 1

If lstProcName.Selected(x) = True Then
Me.ProcedureNamesCodes = Me.ProcedureNamesCodes & lstProcName.Column(0) & lstProcName.Column(1) & vbCrLf
End If
Next

If I select 2 data items, this will loop thru twice but only put the data of the first item into the textbox twice.

This is logical as I haven't specified which line.


If I use the following code which specifies the items I want, the loop is only processed once, although I select 2 data items. I can't see why:

For x = 0 To lstProcName.ListCount - 1

If lstProcName.Selected(x) = True Then
Me.lstProcName.BoundColumn = 1
Me.ProcedureNamesCodes = Me.ProcedureNamesCodes & Me.lstProcName.ItemData(x) & " "
Me.lstProcName.BoundColumn = 2
Me.ProcedureNamesCodes = Me.ProcedureNamesCodes & Me.lstProcName.ItemData(x) & vbCrLf
End If
Next


Can anyone suggest a reason? Thanks

Geoff.
 
Code:
For x = 0 To lstProcName.ListCount - 1
    If lstProcName.Selected(x) Then
        Me.ProcedureNamesCodes = Me.ProcedureNamesCodes & _ 
            Me.lstProcName.column(1, x) & " " & Me.lstProcName.column(2, x) 
    End If
Next [COLOR="Red"][B]x[/B][/COLOR]
hth.
 
Thanks very much. I can't believe I overlooked that!
 

Users who are viewing this thread

Back
Top Bottom