C
Clark via AccessMonster.com
This problem has plagued me so long I've reduced it to one combo box on one
form and one table to eliminate extraneous input. The table has two fields,
WordID and Word. The combo box allows the user to enter a word. If it is
not in the table, a message box asks if he/she wants to add it. If yes,
messagebox disappears and the generic messagebox opens with "The item you
entered isn't an item in the list." The entered word remains visible in the
combo box, though it has been entered into the table.
Limit to List = yes. Auto Expand = yes.
The code is:
Private Sub Word_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String
'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Word ...")
If i = vbYes Then
strSQL = "Insert Into tblWord(Word) values ('" & NewData & "')"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Any ideas?
form and one table to eliminate extraneous input. The table has two fields,
WordID and Word. The combo box allows the user to enter a word. If it is
not in the table, a message box asks if he/she wants to add it. If yes,
messagebox disappears and the generic messagebox opens with "The item you
entered isn't an item in the list." The entered word remains visible in the
combo box, though it has been entered into the table.
Limit to List = yes. Auto Expand = yes.
The code is:
Private Sub Word_NotInList(NewData As String, Response As Integer)
Dim strSQL As String
Dim i As Integer
Dim Msg As String
'Exit this sub if the combo box is cleared
If NewData = "" Then Exit Sub
Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Word ...")
If i = vbYes Then
strSQL = "Insert Into tblWord(Word) values ('" & NewData & "')"
CurrentDb.Execute strSQL, dbFailOnError
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
Any ideas?