Adding items to a list box in Access 2000

A

Antonio

I am trying to add items to a list box at runtime and I
haven't found anything like AddItem in Access 2000. The
items that would be in the list box would be copied from a
text box. Any idea? Thanks
 
C

chas

Hi,

AddItem was not added to Access' ComboBoxes/ListBoxes
until version 2002. You could look at using a
RowSourceType of ValueList which uses a semi-colon
seperated list of values in the RowSource property and
concatenate the new values to this string. Or you could
use DAO or ADO code to add new records to a table that
fills the ListBox and then requery it.

Anyone out there got any examples?

hth

chas
 
A

Antonio

What I am trying to do is:

when a user enters an IP address in a text box and clicks
on Add, I want that IP address to be entered into a
listbox.
 
A

Antonio

It doesn't add anything
-----Original Message-----
Add something like this to the Click event of your button:

If Len(Me!List1.RowSource) > 0 Then Me!List1.RowSource =
Me!List1.RowSource & ";" & Me!Text1
Else: Me!List1.RowSource = Me!Text1
End If



.
 
S

Sherrie

Not sure why it wouldn't work for you but let me walk you
thru how it works in my app.

I've created a form, added a text box for input, a command
button and a list box. I opened the Properties sheet for
the command button, selected the 'On Click' event then
selected "Code Builder" after hitting the button with
the '...' to the right of 'On Click' event field.

This then opens up the VBA editor with the cursor sitting
within the 'Sub' procedure for 'Click'. Add the code from
my previous post, making sure the lines break where they
should for an 'If..Then..End If' condition. Save.

Return to the form, and select 'View' mode. Type in any
text in the Text box, click the 'Add' button you created
and watch the text be added to the List box.

I have used this code in several apps, if it's giving you
problems check for some basic syntax errors and try again.

Sherrie
 

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