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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

list boxes

Status
Not open for further replies.

weltergon

MIS
Oct 1, 2002
21
US
Hi,
How can I concatenate all selected items in a listbox and assign them to a string variable, in order to form a select statement?
Thanks
 
weltergon,

I am not sure what you are looking for in the SQL select statement but the following will take and add OR between all the value which have been selected in a multi select listbox.

As you can see this code was set up for the click of a button but you can associated with the event that will work best for you.

Private Sub Command2_Click()
Dim strItems As String
Dim varItm As Variant
Dim cntr As Integer

For Each varItm In List0.ItemsSelected
cntr = cntr + 1
If cntr < List0.ItemsSelected.Count Then
strItems = strItems & List0.Column(0, intCurrentRow) & &quot; OR &quot;
Else
strItems = strItems & List0.Column(0, intCurrentRow)
End If
Next varItm
MsgBox (strItems)
End Sub

HTH,

Steve
 
Thank You very much. This works; however it retrieves just the row number is there anyway I can retrieve the actual data for example if I select the first option in the list box the code returns 1 and the first option is Concept...is there anyway I can get it to return Concept instead of the value 1?
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top