I am using the following code on a combo box for a NotOnList event. For some reason, VB chokes on the Insert statement with the 424 error. Thanks in advance.
Private Sub Combo44_NotInList(NewData As String, Response As Integer)
'Ask the user if they want to add to the list
If MsgBox("This equipment does not exist. Do you want to add it?", vbYesNo + vbQuestion, "Add new value?") = vbYes Then
'The user clicked Yes - add the new value
db.Execute "INSERT INTO [Equipment List] (Equipment) VALUES (""" & NewData & """)", dbFailOnError
'Tell Access you've added the new value
Response = acDataErrAdded
Else
'The user clicked No - discard the new value
Me.Combo44.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue
End If
db.Close
End Sub
Private Sub Combo44_NotInList(NewData As String, Response As Integer)
'Ask the user if they want to add to the list
If MsgBox("This equipment does not exist. Do you want to add it?", vbYesNo + vbQuestion, "Add new value?") = vbYes Then
'The user clicked Yes - add the new value
db.Execute "INSERT INTO [Equipment List] (Equipment) VALUES (""" & NewData & """)", dbFailOnError
'Tell Access you've added the new value
Response = acDataErrAdded
Else
'The user clicked No - discard the new value
Me.Combo44.Undo
'Tell Access you've discarded the new value
Response = acDataErrContinue
End If
db.Close
End Sub