NotInList..add NewData

G

Guest

Got this from an old Newsgroup Post...
Adding a value to the combo's value list.
If the combo's list is hard-coded in it's RowSource property as a value
list, you have to add the value, as shown below:

Private Sub Combo0_NotInList(NewData As String, Response As Integer)
'Add the value to the RowSource property
Me.Combo0.RowSource = Me.Combo0.RowSource & ";" & NewData
'Tell Access you've added the new value
Response = acDataErrAdded
End Sub

The above works for a Bound Field...but when I tried it for a textbox on an
unbound Form, it didn't work...Is that true, or did I do something incorrect?

TIA - Bob
 
B

Brendan Reynolds

Bob Barnes said:
Got this from an old Newsgroup Post...
Adding a value to the combo's value list.
If the combo's list is hard-coded in it's RowSource property as a value
list, you have to add the value, as shown below:

Private Sub Combo0_NotInList(NewData As String, Response As Integer)
'Add the value to the RowSource property
Me.Combo0.RowSource = Me.Combo0.RowSource & ";" & NewData
'Tell Access you've added the new value
Response = acDataErrAdded
End Sub

The above works for a Bound Field...but when I tried it for a textbox on
an
unbound Form, it didn't work...Is that true, or did I do something
incorrect?

TIA - Bob


Do you really mean that you tried it for a text box, Bob, or was that a
typo? It won't work for a text box, bound or unbound, it only works for
combo boxes.

With combo boxes, this technique will add the new value to the list only
while the form remains open. When the form is closed, the change will be
discarded. It's a design change, and design changes can't be permanently
saved without opening the form in design view.

Generally speaking, if you want the user to be able to add items to the
list, it is best to use a table and not a value list.

If this still doesn't answer your question, perhaps you could post a little
more information about how you tried to use the code, and what happened when
you tried?
 
G

Guest

Yes, it has to be a ComboBox...I should have said that.

I thought this was the only way...now I know..thank you - Bob
"Generally speaking, if you want the user to be able to add items to the
list, it is best to use a table and not a value list."
 

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