Add-to Combo box

R

Rick

I need to write an event proceedure that will an item to the table I use as a
combo boxes control source.
 
P

Perry

Below sequence examplifies List2 (listbox) with control
source pointing to table1 (3 fields, type Text)
This adds a new entry in the listbox ...
Eventhough below example is useless, it adds an entry to yr list or
combobox, as that is what you asked

Is there anything you can pick up from below sequence?
If not, pls indicate what y're after.

Private Sub List2_DblClick(Cancel As Integer)
CurrentProject.Connection.Execute _
"insert into table1 values ('123', '32', 'asdf')"

Me.List2.Requery
End Sub

Krgrds,
Perry
 
R

Rick

Ok. I have a combo box on a form labled "Model" that corresponds to table of
the same name. Since new models are added all the time, I need to be able to
add them to the table directly from the combo box.
 
P

Perry

You will need to check whether new models are not already in yr table.
Look at NonInList event
Something like:

Private Sub Combo7_NotInList(NewData As String, Response As Integer)

If MsgBox("New model. Enter in list?", vbYesNo) = vbYes Then
Me.Combo7.ControlSource = ""
CurrentDb.Execute "insert into model values ('" & NewData & "')"
Me.Combo7.Requery
Else
Me.Combo7.Dropdown
End If
Response = acDataErrContinue
End Sub

Krgrds,
Perry
 
P

Perry

small correction (too fast reply:)

Private Sub Combo7_NotInList(NewData As String, Response As Integer)

If MsgBox("New model. Enter in list?", vbYesNo) = vbYes Then
CurrentDb.Execute "insert into model values ('" & NewData & "')"
Response = acDataErrAdded
Else
Me.Combo7.Dropdown
Response = acDataErrContinue
End If
End Sub
 
R

Rick

Thanks Perry. This works great.

Perry said:
small correction (too fast reply:)

Private Sub Combo7_NotInList(NewData As String, Response As Integer)

If MsgBox("New model. Enter in list?", vbYesNo) = vbYes Then
CurrentDb.Execute "insert into model values ('" & NewData & "')"
Response = acDataErrAdded
Else
Me.Combo7.Dropdown
Response = acDataErrContinue
End If
End Sub
 
Top