Add Data To A Listbox

indesisiv

Access - What's that?
Local time
Today, 19:25
Joined
Jun 13, 2002
Messages
265
I have a list box and i want it to act like a combobox in the sense that i want to be able to add data to it. (As in notinlist sort of thing)

I have a textbox so that the user can type in something and then click a button and add it to the list box.


The listbox is unbound and the row source is based on a table so the data just needs to be added to the table.

I am sure that this is something obvious so i apologise in advance. Any help will be gratefully received.

Steve
 
There is no obviously easy way to add data to a listbox or combobox. Just as in the case with the combobox, you must add the data to the control's rowsource and then requery the listbox.

You can either add the data to the underlying table, or temporarily add it to the rowsource using a union query.

You mention adding the data to a table in your post, so I'll go over that. Open the table in code using VBA as a recordset, add a new record to the recordset, close the recordset, requery your listbox, and you're done. I can be more precise if you tell me which version of Access you are using and (if you know) more specifically if you're using DAO or ADO.
 
I am using Access 97 and DAO i think.
 
I've attached a simple example in Access 97 format that demonstrates the technique. It's set up for text values. If you want to use it for numeric fields, just remove the single quotations characters bracketing the criteria in the rst.FindFirst line.
 

Attachments

Thanks dcx693 that is exactly what i needed.
:D
Steve
:D
 
No prob Steve. Glad to give something back to the Brits on July 4th! :D
 

Users who are viewing this thread

Back
Top Bottom