Duplicate field entries with combobox

D

Duck

I have a form which employs a couple of combo boxes that allow me to
enter Vendor and Model information into a table. The combo boxes
employ a SELECT DISTINCT query to populate the lists. I am now trying
to add a warning message if a value that is not in the list is
entered.

Private Sub cboUnbound_NotInList(NewData As String, Response As
Integer)
Dim cnn As New ADODB.Connection
Dim strSQL As String
Dim bytResponse As Byte
Set cnn = CurrentProject.Connection
bytResponse = MsgBox("Do you want to add this new item " _
& "to the list?", vbYesNo, "New Item Detected")
If bytResponse = vbYes Then
strSQL = "INSERT INTO Colors(Colors) VALUES('" _
& NewData & "')"
Debug.Print strSQL
cnn.Execute strSQL
Response = acDataErrAdded
ElseIf bytResponse = vbNo Then
Response = acDataErrContinue
Me!cboUnbound.Undo
End If
End Sub

The problem is that when I reply 'yes' to the msgbox I get an extra
entry in the destination table with just the one field bound to the
combobox and the new value. So I get one complete record and another
record with a value in only one field. What am I doing wrong.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top