Setting values in a multi-select list box.

G

Guest

I'm trying to select a particular value in a multi-select list box. I have a
search function that searches the records in a multi-select list box and
returns the value of the first item that matchs the search string. It then
selects this item in the list box for the user. The problem is, it works
fine when the list box's Multi-select property is set as NONE. But when I
select SIMPLE or EXTENDED, it doesn't work. Instead, no records are
selected. It also appears the default value property doesn't work either.
Any suggestions on getting around this?

Craig
 
V

Van T. Dinh

Multi-Select ListBox always has Null Value and you cannot set the Value of a
Multi-Select ListBox.

It sounds like you can use the Property "Selected" of the Multi-Select
ListBox. Check Access Help on this Property which has sample codes.
 
D

Douglas J. Steele

Here's sample code from the Help file:

Sub BoundData()
Dim frm As Form, ctl As Control
Dim varItm As Variant

Set frm = Forms!Contacts
Set ctl = frm!Names
For Each varItm In ctl.ItemsSelected
Debug.Print ctl.ItemData(varItm)
Next varItm
End Sub
 
G

Guest

Should have come back to thank you folks for the help on this. I got this to
work finally using the "selected" property and setting it to True for the
item(s) I wanted selected. As an add-on to folks using this in the future,
you must also include code to identify the items ALREADY selected and set
them all to "False". Otherwise you just keep selecting additional items.

Have a new question though. Lets say there are 10 rows of records displayed
at any one time in the list box but say there are 2000 possible selections.
My search code finds the record and selects it with no problem. But the
selected record is not moved into the visual part of the list box. In other
words, I'd have to scroll down through the list until I see it. I want the
selected record to be 'jumped' to.

Any thoughts?

Craig
 

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