.AddItem function

A

Alex

Hi...ok I am stump. I have two list boxes let's call
them, lstVendors and lstAddedVendors. I want to add items
in my lstVendors to my lstAddedVendors. I have the
command button cmdAddVendor. Now the current code I have
is Private Sub cmdAddVendor_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant
Set frm = Forms!ByCourse
Set ctl = frm!lstCourseName
Dim count As Integer
' loop through each item they've selected and add it
to 'added courses'
For Each varItm In ctl.ItemsSelected
lstAddedVendors.AddItem (ctl.ItemData(varItm))
Next varItm
ctl.Requery
End Sub

Now this is from another database, for some reason when I
click on the button..it goes error .AddItem, the method
doesn't exist. Now I believe that the method is private
stored in some other database or something. How would I
create my own function off AddItem?? I just want to add
one item from one list box to the next. I know it's
asking a lot, but I'm stumped would be great help.

-Thanks
 
G

Gerald Stanley

The version of the listbox (and combobox) control that
comes standard with Access does not have the AddItem
method. The only way I know of changing the dropdown list
of a list box with a RowSourceType of 'Value List' is to
change the RowSource string. So you could try
For Each varItm In ctl.ItemsSelected
lstAddedVendors.RowSource = lstAddedVendors.RowSource &
";" & ctl.ItemData(varItm)
Next varItm

Hope This Helps
Gerald Stanley MCSD
 
A

ALEX

I came up with that but the only problem is that if I
select another item from lstbox 1 to add to lstbox 2...it
will replace the item and not add it in. So I will have
Green in list box 2 and then add Red..Red will replace
Green instead of just adding in. I think there are a
bunch of codes for this.

Dim varItm As Variant

Me.lstAddedVendors.RowSource = vbNullString
For Each varItm In Me.lstVendors.ItemsSelected
Me.lstAddedVendors.RowSource =
Me.lstAddedVendors.RowSource & Me.lstVendors.ItemData
(varItm) & ";"
Next varItm
Me.lstAddedVendors.Requery
 
B

Brendan Reynolds

Slight clarification - prior to Access 2002, Access list box and combo box
controls did not have these methods. They have them in Access 2002 and
later.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

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