janed
02-26-2002, 05:16 AM
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?
|
View Full Version : adding entries to combo boxes janed 02-26-2002, 05:16 AM 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? SimonC 02-26-2002, 02:10 PM 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 |