ADDING values from one listbox to another on same form

C

CompleteNewb

I want to be clear, because I know that BASING one listbox on another is a
common question, but this is NOT basing one on the other; What I would like
to do is ADD values from one to the other.

Let's say I have 2 listboxes, one on the left, one on the right. The left
one will have a source of a table. When the user double clicks one value in
this litbox (or highlights it and clicks a button), I would like that value
to appear in the right listbox. If the user doubleclicks another value in
the left listbox, I'd like that value to be ADDED (or perhaps a better word
would be "INCLUDED"; we're not talking arithmetic) to the right listbox (so
now the right listbox shows 2 values).

I'm hoping, in the very near future, to have queries use the values in the
listbox on the right as criteria.

So, when form initially opens, you have:

LeftListbox RightListbox
String1
String2
String3
String4
String5

Then the user doubleclicks the "String4" value (or selects it and clicks a
button). You now see:

LeftListbox RightListbox
String1 String4
String2
String3
String4
String5

Then the user doubleclicks the "String2" value. Now you see:

LeftListbox RightListbox
String1 String4
String2 String2
String3
String4
String5

It would be great if the user could also remove values from the righthand
listbox by doubleclicking them (or highlighting them and clicking a
different button). My plan, here, is to have a query use the strings in the
right listbox as criteria, as in "Select * From [whatever] Where [Field1] =
"String4" Or "String2"", etc., for as many values as have been placed into
the right listbox.

Can anyone help me with this? I've tried having the left listbox update a
table, which the right listbox is based on, and requerying every time a
value is chosen, but this isn't working. Plus it seems like an extra step
to make a table and dynamically update it just to populate a different
listbox. I also started trying to make an array of variables in VBA, but
neither my attempts to add to the array nor my attempts to use that array as
a query criteria in my design grid was working.

Any help with this would be very much apreciated. And, if you think I'm
approaching the whole concept the wrong way, I'm open to better ways of
allowing users to choose several items from a table and use those choices as
the criteria in a query (same field, just every chosen value is added to the
"Or" statement of that field's criteria in the query; so if the user has
doubleclicked "String1" and "String2" and "String3," the query would have in
the criteria line of the field being queried "String1" Or "String2" Or
"String3"

Thanks for reading, and for any help.
 
M

Mike Painter

CompleteNewb said:
Let's say I have 2 listboxes, one on the left, one on the right. The
left one will have a source of a table. When the user double clicks
one value in this litbox (or highlights it and clicks a button), I
would like that value to appear in the right listbox. If the user
doubleclicks another value in the left listbox, I'd like that value
to be ADDED (or perhaps a better word would be "INCLUDED"; we're not
talking arithmetic) to the right listbox (so now the right listbox
shows 2 values).

It would be great if the user could also remove values from the
righthand listbox by doubleclicking them (or highlighting them and
clicking a different button). My plan, here, is to have a query use
the strings in the right listbox as criteria, as in "Select * From
[whatever] Where [Field1] = "String4" Or "String2"", etc., for as
many values as have been placed into the right listbox.
You would have to set the rowsource for the second list box to the values
selected in an on click event in the first list box and remove them in a
second.
Me.secondlistbox.rowsource = ListBoxList &";" & me.firstlistbox
Then requery.
Unless you store those values it will have to be done every time.

You could use a multi-select list box.

I and more importantly my clients have always liked the way I do it.
I add a boolian field named "PrintThis" to teh table I am working with.
I create a subform that looks like a list box and include the "PrintThis"
field.
Two buttons are added to the top of this form. "Select All" and "Clear All"
The user checks off the values they want to use and runs a report based on
"PrintThis = True".
It is persistant and there is no need for a second box.
If you still wanted teh second box it would be simple to base the right form
on "PrintThis = True" and if you wanted the left box on "PrintThis = False".
The values would disappear from the one and appear on the other.
 

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