By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

Help with multi-select listbox

P: n/a
I am using Access 2000. I have the Developer's handbook and got the
code for the mulit select listbox from there. It sends the selected
value to another listbox, lstselected. What I need to do is loop
through there and add each item to a table. I can add the other info
fromt he form to a table, just not the otems in the listbox. It only
shows as 0. I tried using the varItem and it told me that the action
is not supported. I'm a bit rusty in my Access programming so any help
is appreciated. Thanks.

Melissa Cowan
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
mc****@gaf.com (Melissa Cowan) wrote in message news:<25**************************@posting.google. com>...
I am using Access 2000. I have the Developer's handbook and got the
code for the mulit select listbox from there. It sends the selected
value to another listbox, lstselected. What I need to do is loop
through there and add each item to a table. I can add the other info
fromt he form to a table, just not the otems in the listbox. It only
shows as 0. I tried using the varItem and it told me that the action
is not supported. I'm a bit rusty in my Access programming so any help
is appreciated. Thanks.

Melissa Cowan


there's code at mvps.org for looping through the selecteditems
collection of a listbox. Then you'd just open a recordset based on
the table and then use the .Add method to add a new record, .Edit it,
then .Update it once you've made all your additions. Nothing doing.
Should all be under "Recordset" in the help.
Nov 13 '05 #2

P: n/a
Hmm, well, I've looked there and can't find anything that works. I've
found an article on passing values from a mulit-select box to a query
but nothing about how to loop through itmes in a listbox and add it to
a table. I just really need info on how to go through the items in a
listbox. I've got the code to add the records to a table and that part
works. It just won't pick up each name in the SelectedItems box and
add it. I'm assuming I need to loop through each name in that box as
the names get sent over to it from the listbox with all the Employee
names in it. Am I correct? Thinking wrong? Trying to be too complex on
my form?

Melissa
pi********@hotmail.com (Pieter Linden) wrote in message news:<bf**************************@posting.google. com>...
mc****@gaf.com (Melissa Cowan) wrote in message news:<25**************************@posting.google. com>...
I am using Access 2000. I have the Developer's handbook and got the
code for the mulit select listbox from there. It sends the selected
value to another listbox, lstselected. What I need to do is loop
through there and add each item to a table. I can add the other info
fromt he form to a table, just not the otems in the listbox. It only
shows as 0. I tried using the varItem and it told me that the action
is not supported. I'm a bit rusty in my Access programming so any help
is appreciated. Thanks.

Melissa Cowan


there's code at mvps.org for looping through the selecteditems
collection of a listbox. Then you'd just open a recordset based on
the table and then use the .Add method to add a new record, .Edit it,
then .Update it once you've made all your additions. Nothing doing.
Should all be under "Recordset" in the help.

Nov 13 '05 #3

P: n/a
Ok, I solved my own problem. I used the listcount and then loop
through the listbox while a number I'm incrementing is less than that.
Here is the code for what I did. If anyone has any better suggestions
than that I am always open to them.

Dim db1 As DAO.Database
Dim rs1 As DAO.Recordset
Dim ItemCount As Long
Dim Counting As Long

ItemCount = lstSelected.ListCount
Counting = 0
Set db1 = CurrentDb()
Set rs1 = db1.OpenRecordset("MultiSelectAction")

With rs1
While Counting < ItemCount
.AddNew
![CPAR_ID] = txtCPAR_ID.Value
![Employee] = lstSelected.Column(0, Counting)
![ActionNumber] = ActionID.Value
.Update
Counting = Counting + 1
Wend
End With
Thanks.
Melissa Cowan
Nov 13 '05 #4

P: n/a
Here's what I use:

For Each i In Me![lstbox].ItemsSelected
blah = blah & Me![lstbox].ItemData(i)
Next i

HTH

Jan

Hmm, well, I've looked there and can't find anything that works. I've
found an article on passing values from a mulit-select box to a query
but nothing about how to loop through itmes in a listbox and add it to
a table. I just really need info on how to go through the items in a
listbox. I've got the code to add the records to a table and that part
works. It just won't pick up each name in the SelectedItems box and
add it. I'm assuming I need to loop through each name in that box as
the names get sent over to it from the listbox with all the Employee
names in it. Am I correct? Thinking wrong? Trying to be too complex on
my form?

Melissa
pi********@hotmail.com (Pieter Linden) wrote in message
news:<bf**************************@posting.google .com>...
mc****@gaf.com (Melissa Cowan) wrote in message

news:<25**************************@posting.google .com>...
> I am using Access 2000. I have the Developer's handbook and got the
> code for the mulit select listbox from there. It sends the selected
> value to another listbox, lstselected. What I need to do is loop
> through there and add each item to a table. I can add the other info
> fromt he form to a table, just not the otems in the listbox. It only
> shows as 0. I tried using the varItem and it told me that the action
> is not supported. I'm a bit rusty in my Access programming so any help
> is appreciated. Thanks.
>
> Melissa Cowan


there's code at mvps.org for looping through the selecteditems
collection of a listbox. Then you'd just open a recordset based on
the table and then use the .Add method to add a new record, .Edit it,
then .Update it once you've made all your additions. Nothing doing.
Should all be under "Recordset" in the help.


Jan Stempel
Stempel Consulting
Nov 13 '05 #5

P: n/a
Forgot to add, you have to dim the i as integer (or, I seem to have done it as
variant in my last use; not sure why).

Jan
Jan Stempel
Stempel Consulting
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.