multi-select list box

G

Guest

I would like to make a list box in form. The form shows information of
different people. Each people can choose certain food from a list of them
(select the whole list available as the row source). I would like the listbox
display the food a person chosen as selected (multi-selected). People can
then view and re-select the food using the list box.

Can I implement such kind of things in a form? I hope I make the situation
clear enough for you to answer. Thank you for help!
 
M

Michel Walsh

Hi,


Sure you can.


You can clear then select the values you want through the Selected(
indexPosition )

The following will clear the selected items, then select those where the
"key field" value is either 1, 2, or 4


Dim i As Long

For i = 0 To Me.List0.ListCount - 1

Me.List0.Selected(i) = False ' clear the selection

If Eval(Me.List0.ItemData(i) & " IN(1, 2, 4) ") Then
Me.List0.Selected(i) = True
End If

Next i




In practice, you can use one loop to clear, and one loop to "select"what has
to be select, here, I just make an example "for illustration". The main
point is to assign the ListBoxControl.Selected( indexPosition ) to true
(selected) or false (not selected). You would probably elect to do that in
the onCurrent event.


To capture back the selected data, in the FORM before update event, as
example, you can walk across the ItemsSelected collection, rather than using
the same kind of loop.



Hoping it may help,
Vanderghast, Access MVP
 

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

Top