ListBox multiple choices

  • Thread starter Thread starter Lee Harwell
  • Start date Start date
L

Lee Harwell

I need code for making my listbox multiple choices from a
Search form open up in another (Detail) form.

Each item in the listbox represents a record that I want
to filter so that when a users navigates from one record
to the next in the opened form, they can only move to the
records selected in the list.

I have not been able to find any examples on how to do
this. Can
you provide me with some.
Thanks, Lee

My Search form form is called : NameLookupForm
In this form is a listbox based on a query which lists
the first column called "ComputerNo" a( whole integer).


The detail form is called: NameDetailForm
 
Hello Lee,

The only way how I can think of to do this is to keep track of what is
selected in the listbox in a table (you may be able to add a field in the
existing table you are using and add a yes/no field in there). Once you know
what is checked in the text box you can use the IN part of the SQL statement
and use the query as a sub query. e.g.

SELECT tblOutput.* FROM tblOutput WHERE ComputerNo IN (SELECT
qryMyQuery.ComputerNo FROM qryMyQuery WHERE qryMyQuery.blnIsSelected = True)

The line above will filter out all records in your query were the check box
(blnIsSelected) has been ticked. In other words, you will have a query that
has returned each ComputerNo that has been selected in your listbox. These
values returned are then checked in the outer query and all ComputerNo
matches in the sub query will be found in the main query and then the
results would be shown in the newly opened form.

This is just a made up SQL statement, but should give you some ideas on what
you can do. This could be saved as another query or used as the opening
forms RowSource directly. The key to this is keeping track of what the user
has checked in the listbox. You could use the ListBox's on click event and
use the Selected property and then update the yes/no field in the
table/query using code.

HTH,

Neil.
 
If you have a list box with the Multi Select set to simple or extended then
you have to perform a "For...Each...Next" type loop function to find each
item in the list that was selected. At the end of the loop you will have a
listing of the items selected. See "List Box" "Multi Select" in the help
file. There is a good explanation with good examples.

Cheers,
Henry
 
Back
Top