Populate control with Items from MultiList Box

S

Shelly Jackson

How do I populate a control on my form with the items selected from a
multilist box?

I tried this link: http://www.mvps.org/access/forms/frm0007.htm

But, I could not figure it out.

The name of my form is: fdlgRptsSingle
The list box is named: RegListBx
The control is named: RegSelect

TIA
S. Jackson
 
J

John Vinson

How do I populate a control on my form with the items selected from a
multilist box?

You don't.

Data is not stored in a Form. It's stored in a Table; a Form is just a
tool to see and manage data in Tables.

And you don't store multiple values in a field in any case. A Field in
a table must be "atomic" - have one and only one value.

You may need a second Table, related one-to-many to your current
table; you can use a Subform to enter data into it, or (with some
fairly fancy VBA code) use a listbox for that purpose.
 
S

Shelly Jackson

oops, I think I may have caused a misunderstanding. I am not trying to
"store" the information into a table.

I have a multilist box in which a user selects "Regions." The user then
selects a report and the report prints based on what "regions" the user has
selected. I want the report to indicate what "regions" the user selected.
I was trying to follow along with the example at the link I posted below
which says you pass the Where clause via code to a parameter (e.g. have the
query reference a hidden control), but I am having trouble. I do not know
where to put the code shown in the example, AfterUpdate on the RptListBox,
or somewhere in my report? I also can't figure out what to plug in where.
The example references Employees and [EmpID]. Where did this come from? A
table, a report, a query? so lost here.

My RptListBox source table is LU_Regions which only has one field,
[Regions].

Any help is appreciated.

S. Jackson
 
F

Fredg

Shelly,
To fill an unbound control with the multi-selected items of a list box:

In the List Box Exit event:

Dim strList as String
Dim varItem As Variant
For Each varItem In RegListBx.ItemsSelected
strList = strList & RegListBx.Column(0, varItem) & ", "
Next varItem
strList = Left(strList, Len(strList) - 2)
[RegSelect] = strList
RegListBx = Null

The result would look like this:
East, North
if those were the two items selected.

Change
ListName.Column(0,varItem)
to the actual list box name and the correct column number.
Column 0 is the first column.
 
S

Shelly Jackson

MANY, MANY THANKS! It worked!

I truly mean it - thank you for taking the time to help me out.
S.Jackson

Fredg said:
Shelly,
To fill an unbound control with the multi-selected items of a list box:

In the List Box Exit event:

Dim strList as String
Dim varItem As Variant
For Each varItem In RegListBx.ItemsSelected
strList = strList & RegListBx.Column(0, varItem) & ", "
Next varItem
strList = Left(strList, Len(strList) - 2)
[RegSelect] = strList
RegListBx = Null

The result would look like this:
East, North
if those were the two items selected.

Change
ListName.Column(0,varItem)
to the actual list box name and the correct column number.
Column 0 is the first column.
--
Fred

Please reply only to this newsgroup.
I do not reply to personal e-mail.


Shelly Jackson said:
How do I populate a control on my form with the items selected from a
multilist box?

I tried this link: http://www.mvps.org/access/forms/frm0007.htm

But, I could not figure it out.

The name of my form is: fdlgRptsSingle
The list box is named: RegListBx
The control is named: RegSelect

TIA
S. Jackson
 

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