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

List Box

P: n/a
Hi

I want to add an item (string) to a list box that is already on the form in
the form_open procedure, but it wont work. Can't I just type
me.listname.addItem item:= "blabla" to add a single string to the list? Or
do I have to do something more with the list box?

--
Vegard
Nov 12 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Try in a different event; as the Controls may not be initialized during
Open... use the Load event, as a first try.

Also, AddItem only works on List and Combo Boxes which have the ValueList
option selected, not those bound to a RowSource.

Larry Linson
Microsoft Access MVP

"Vegard H. Villmones" <vv******@c2i.net> wrote in message
news:3q*******************@news4.e.nsc.no...
Hi

I want to add an item (string) to a list box that is already on the form in the form_open procedure, but it wont work. Can't I just type
me.listname.addItem item:= "blabla" to add a single string to the list? Or
do I have to do something more with the list box?

--
Vegard

Nov 12 '05 #2

P: n/a
The last thing to occur when a form opens is the controls populate the form so
there is no form event that will allow you to add something to a listbox on the
form. To achieve what you want you need to add the item to the source of the
data for the listbox before you open the form. You can do this by creating a
recordset of the source and then use the Add/Update method of the recordset.
This can all be done in one procedure:

Create Recordset
Add/Update item to recordset
Open the Form

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
www.pcdatasheet.com
"Vegard H. Villmones" <vv******@c2i.net> wrote in message
news:3q*******************@news4.e.nsc.no...
Hi

I want to add an item (string) to a list box that is already on the form in
the form_open procedure, but it wont work. Can't I just type
me.listname.addItem item:= "blabla" to add a single string to the list? Or
do I have to do something more with the list box?

--
Vegard

Nov 12 '05 #3

P: n/a
"Vegard H. Villmones" <vv******@c2i.net> wrote in message news:<3q*******************@news4.e.nsc.no>...
Hi

I want to add an item (string) to a list box that is already on the form in
the form_open procedure, but it wont work. Can't I just type
me.listname.addItem item:= "blabla" to add a single string to the list? Or
do I have to do something more with the list box?


If you want to do that, you have to append it to the rowsource and
then requery. you're thinking in VB, not VBA. (I know... doesn't
make sense, but that's the way listboxes work in Access...

Pieter
Nov 12 '05 #4

P: n/a
Access 2002 and 2003 both have an AddItem method for ListBoxes populated
from a ValueList, Pieter. There's also been a method for filling a List or
Combo box from a callback function since at least Access 2.0.


Nov 12 '05 #5

P: n/a
bo*****@localhost.net (Larry Linson) wrote in
<3m*******************@nwrddc03.gnilink.net>:
Also, AddItem only works on List and Combo Boxes which have the
ValueList option selected, not those bound to a RowSource.


And .AddItem did not exist until A2K3, no?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #6

P: n/a
bo*****@localhost.not (Larry Linson) wrote in
<hs*******************@nwrddc01.gnilink.net>:
Access 2002 and 2003 both have an AddItem method for ListBoxes
populated from a ValueList, Pieter. There's also been a method for
filling a List or Combo box from a callback function since at
least Access 2.0.


But I think Pieter's point was that in a database application, it
makes more sense to populate a listbox with a SQL string than with
a list, as you would in a VB app, where you most often don't have a
database to draw the list items from.

That said, of course we all sometimes need listboxes that aren't
populated via SQL.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.