I have combo box based on one Field which is PK and i have use following code for the NotInList event of combo to add new data to the table. This code works fine since there is one field in table.
Now i also have another combo box that is based on table which has 3 fields such as
ID.....FName.......LName........How can i use this code to enter new data from combo box using NotInList event ?
Dim strsql As String, x As Integer
x = MsgBox("Do you want to add this value to the list?", vbYesNo)
If x = vbYes Then
strsql = "Insert Into tblClinics ([ClinicName]) values ('" & NewData & "')"
CurrentDb.Execute strsql, dbFailOnError
Response = acDataErrAdded
Response = acDataErrContinue
I was just doing the same thing with the notinlist event. I had a table with one field and it worked fine. I expanded it to 4 fields and it stopped working.
I looked into it and found the problem was I made the id field the key which did not allow duplicates. It was not an autonumber field- I removed the key designation and it worked because the entry was comming in with the id field defaulting at 0. I had used the ID field to allow arranging in a custom order. One of the risks you run when you modify an existing table structure rather than designing one correctly from scratch.