Forms List box relations

E

EWAPOOS

How do I relate two list boxes on a form? I want to populate one list box
automatically depending on the first list box value or selection. ie. When I
select a PersonID ın the first list box I want the second box to populate the
name automatically that is related to the selected ID.
 
M

Maurice

You could try using a query as a source for your second listbox. Set the
parameter (PersonID) to the first listbox. You'd have to do a requery after
you click on the first listbox to get the results in the second listbox
though.

hth
 
J

Jeff Boyce

If your first listbox is based on a query that returns two columns (e.g.,
PersonID, PersonName), you can base the second listbox on the second column
of the item(s) selected in the first.

I'm not clear on why you want to use listboxes for this, though. Another
approach might be to use a combobox that is based on the same query
(PersonID, PersonName), uses "0" for the width of the first column
(PersonID) and whatever width is needed for the second (PersonName).

This way, your users can pick a person by name, not ID. And the combobox
will be displaying PersonName.

--
Regards

Jeff Boyce
www.InformationFutures.net

Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
A

Al Campagna

Ewapoos,
You wouldn't need a 2nd listbox for that, just one.
Bind the listbox (ex. name lstPersonID) to your PersonID field (which you
probably have already done).
In this listbox show PersonID in the first column, and the PersonName in
the second coulmn.
Set the ColumnCount to 2, and the column widths to 0"; 2".
On your form, place an unbound text control (ex. txtPersonName) with this
ControlSource...
=lstPersonID.Column(1)
(Listboc columns are numbered 0,1,2,3, etc...)
This setup stores the value of lstPersonID to your PersonID field, but
displays the PersonName. In effect, you've made a listbox do double duty.
Get the ID and display the name.

--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
M

MikeB

Jeff Boyce said:
If your first listbox is based on a query that returns two columns (e.g.,
PersonID, PersonName), you can base the second listbox on the second column
of the item(s) selected in the first.

I'm not clear on why you want to use listboxes for this, though. Another
approach might be to use a combobox that is based on the same query
(PersonID, PersonName), uses "0" for the width of the first column
(PersonID) and whatever width is needed for the second (PersonName).

I was wondering also why ListBox would be used to hold 1 item.. which would
lead you to believe there could be a little confusion on the appropriate
control selection.
 

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