adding entries to combo boxes

janed

Registered User.
Local time
Today, 03:13
Joined
Feb 6, 2002
Messages
60
i have a drop down list containing several entries. the field is not limited to list. if a user enters a value not on the list is it possible for it to be added to the list?
 
The trick is to set the LimitToList property of the combo to true - that way you can trap the fact that you're trying to enter something not in the list.

The event that your code goes in is the OnNotInList event. Here's a very rough-and-ready bare-bones kind of example. I'm assuming that the the table in the example is what fills the combo's drop-down list:

Private Sub ComboBoxName_NotInList(NewData As String, Response As Integer)
Dim rec As Recordset

If MsgBox("Value is not in list. Add it?", vbOKCancel) = vbOK Then
Set rec = CurrentDb.OpenRecordset("<table name goes here>")
rec.AddNew
rec!<datafieldname> = NewData
rec.Update
Set rec = Nothing
Response = acDataErrAdded
Else
Response = acDataErrContinue
ComboBoxName.Undo
End If
End Sub

Hope this gets you on the right track.

Simon
 

Users who are viewing this thread

Back
Top Bottom