Add new row in combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello!

I Would like to fill a form only through comboxes.
Doubt:
How to add new options/rows in a combo, please?

Thanks in advance.
an
 
Hi,


If it is based on a table, add the record in the table, then:

Me.ComboBox.RowSource = Me.ComboBox.RowSource

will requery the combo box list.



Hoping it may help,
Vanderghast, Access MVP
 
Why not just Me.ComboBox.Requery ?

On the other hand, if it is a value list you can manipulate the rowsource.
Let's say it is currently: "Janie;Fred;Rocky;Gort" and you want to add Patsy

strValList = Me.ComboBox.RowSource
strValList = strValList & ";Patsy"
Me.ComboBox.RowSource = strValList
 
Hi,


I am not sure all Access versions have the Requery method exposed for a
combo box. That is why I generally use the seemingly moronic statement


Me.ComboBox.RowSource = Me.ComboBox.RowSource


which works on all version, to produce a requery of the rowsource, and of
the list (even in a multi-user environment).


Also note that the main difference between a table and a list of values
augmented at run time is that the table remember the modifications, from
sessions to sessions, while the constant list has to be somehow "re-add"
each time we launch the application, to remember the "previous sessions
run-time added items"... not quite friendly. Also, in a multi-users
environment, the run-time added items will be see only on the local
application, NOT by other users.

That is why using a table sounds, in general, much more profitable than the
"VB way" of using AddItem, or the use of a "constant" list, not really so
constant.


Vanderghast, Access MVP
 
Seems reasonable, but looks weird :)

Michel Walsh said:
Hi,


I am not sure all Access versions have the Requery method exposed for a
combo box. That is why I generally use the seemingly moronic statement


Me.ComboBox.RowSource = Me.ComboBox.RowSource


which works on all version, to produce a requery of the rowsource, and of
the list (even in a multi-user environment).


Also note that the main difference between a table and a list of values
augmented at run time is that the table remember the modifications, from
sessions to sessions, while the constant list has to be somehow "re-add"
each time we launch the application, to remember the "previous sessions
run-time added items"... not quite friendly. Also, in a multi-users
environment, the run-time added items will be see only on the local
application, NOT by other users.

That is why using a table sounds, in general, much more profitable than the
"VB way" of using AddItem, or the use of a "constant" list, not really so
constant.


Vanderghast, Access MVP
 
Sorry for my delay.

I think that I will not have become to understand.
I would like to know if it's possible to add new records without being in
the table directlly.
For example in form;
and add automatically in combobox.

Thanks
an
 
Hi,


No, if the combo box list source comes from a table.

Yes, as shown by Klatuu, is the list source is an immediate list of values.

But "why" not adding it to the table?

DoCmd.Execute "INSERT INTO tableName( field1, fiel2) VALUES(
FORMS!formNameHere!Control1, FORMS!formNameHere!Control2) ", dbFailOnError


is a VBA line of code that add such a record, to a table with 2 fields
(specified). You are not obliged to use a recordset to append data to a
table.


Hoping it may help,
Vanderghast, Access MVP
 
Hi.

Sorry for my ignorance.
I have attemped, without success.
Where the must be placed recommended code, please?
an
 
Hi,


The code can be place in the procedure handling the onclick event of a
button where the main purpose, of that button, is to be clicked to append a
record.

Alternatively, it can be in the NotInList event handler, where the logic
dictates to append the record. If you have the book "Inside Microsoft Access
2003", by John L. Viescas, as example, take a look at pp 863-867. The
Knowledge database also as some example(s) about it (even if the one I
supply here after, uses a recrodset to add the record)
http://support.microsoft.com/kb/824176/en-us



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top