Connecting Tech Pros Worldwide Help | Site Map

Walk Multi Select List Box A2003

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 02:04 PM
SKG
Guest
 
Posts: n/a
Default Walk Multi Select List Box A2003

Hi All

I am using standard code to walk through a multi select list boxes and
build a sql string to filter data, I would also like to store the 2nd
column value for each selected item as well in say strFilter, but seem
to have trouble with the correct syntax / column property

For Each strItem In cntl.ItemsSelected
strSQL = strSQL & cntl.ItemData(strItem) & " Or [staStatusID]= "

Next strItem


Thanks for any help


Steve G


  #2  
Old November 13th, 2005, 02:04 PM
Salad
Guest
 
Posts: n/a
Default Re: Walk Multi Select List Box A2003

SKG wrote:
[color=blue]
> Hi All
>
> I am using standard code to walk through a multi select list boxes and
> build a sql string to filter data, I would also like to store the 2nd
> column value for each selected item as well in say strFilter, but seem
> to have trouble with the correct syntax / column property
>
> For Each strItem In cntl.ItemsSelected
> strSQL = strSQL & cntl.ItemData(strItem) & " Or [staStatusID]= "
>
> Next strItem
>
>
> Thanks for any help
>
>
> Steve G
>[/color]

Not sure I follow. This maight help...
Dim var As Variant
Dim strFilter As String
If me.listbox0.ItemsSelected.Count > 0 then
For Each var In Me.ListBox0.ItemsSelected
'get the second column value in listbox
strFilter = strFilter & Me.ListBox0.Column(1,var) & ", "
next var
'remove comma and add ()
strFilter = "Where [staStatusID]IN " & _
(" & left(strFilter,len(strFilter)-2) & ")"
endif

This might end up like
Where [staStatusID]IN (1,2,3,4,5)

Now you can add the filter to the SQL statement.
strSQL = "Select * From Emp " & strFilter & " Order By EmpName
  #3  
Old November 13th, 2005, 02:04 PM
SKG
Guest
 
Posts: n/a
Default Re: Walk Multi Select List Box A2003

Hi Salad

Yep Thanks for the ideas, just me not thinking very straight. Amended
to read....


For Each strItem In cntl.ItemsSelected
strSQL = strSQL & cntl.ItemData(strItem) & " Or [staStatusID]= "
strFilter = strFilter & cntl.Column(1, strItem) & ", "
Next strItem


A bit of tidying up at the end to get rid of any unwanted spaces &
commas etc etc and easy as you like....

Thanks again for your help in pointing me in the right direction

Cheers

Steve G

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.