Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List box to String conversion 1

Status
Not open for further replies.

lbigk

MIS
May 24, 2002
58
US
Hello,

I cannot find an error in my code:
If ctl.ItemsSelected.Count > 0 Then
For Each varItm In ctl.ItemsSelected
If lstn = "" Then
lstn = Me.lstAcct.Column(2) & ";"
Else
lstn = lstn & ctl.Column(2) & ";"
End If
Next varItm
End If

I should get a list of selected items as a string separated by ";", but I am getting the same value over and over based on the number of items selected in the listbox.

Thank you for your assistance.
 
something more like

Code:
Public Sub listBoxtoString()
  Dim ctl As Access.Control
  Dim varItm As Variant
  Dim lstN As String
  Set ctl = Me.List0
  
  If ctl.ItemsSelected.Count > 0 Then
    For Each varItm In ctl.ItemsSelected
    If lstN = "" Then
       lstN = ctl.Column(1, varItm) & ";"
     Else
        lstN = lstN & ctl.Column(1, varItm) & ";"
     End If
        Next varItm
    End If
    Debug.Print lstN
End Sub

also, remember the second column has an index of 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top