Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo box

Status
Not open for further replies.

PatrickRagan

Technical User
Mar 1, 2002
3
GB
I am using a combo box to select names from a drop down list. When an individual does not appear on that list I would like to add them to it. What is the best way of doing this?
 
Patrick:

In the NotInList property for the box, add:

Dim db As Database, rs As Recordset, strMsg As String, NewItem As Variant

strMsg = "'" & NewData & "' is not in the list"
strMsg = strMsg & "@Do you want to add the item to the list?"
strMsg = strMsg & "@Click Yes to ADD or No to re-type it."
NewItem = NewData
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new item?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("YOUR TABLE NAME", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!FIELD NAME = NewItem
rs.Update

If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If


This should work. "Get it right the first time, that's the main thing..."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top