extract value from listbox

F

Faye

I want to exact the second column of the selected items in the multicolumn
listbox and concatenate them into a string. Before the last item found, I
would like to insert the word "and". This is my code, I am not sure what is
the best way to find the last item in the for loop.

For Each varItm In ctl.ItemsSelected
For intI = 1 To 1 ' intI = 1, so it will pick up second
column only
strTitle = strTitle & " " & ctl.Column(intI, varItm)
Next intI
Next varItm

This string will be used as the title of a report. Thanks.
 
G

George Nicholson

Maybe something like this?

For Each varItm In ctl.ItemsSelected
i = i + 1
Select Case i
Case 1
' First selection
strTitle = ctl.Column(1, varItm)
Case < ctlItemsSelected.Count
' Not first or last selection
strTitle = strTitle & " " & ctl.Column(1, varItm)
Case = ctlItemsSelected.Count
' Last selection
strTitle = strTitle & " and " & ctl.Column(1,
varItm)
Case Else
' i > ctlItemsSelected.Count
MsgBox "Error: Unexpected value in [procedure name].
This shouldn't happen."
End Select
Next varItm

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top