[AccessD] Not in List and adding to a table

Nancy Lytle nancy.lytle at auatac.com
Wed Apr 23 10:54:50 CDT 2003


I am trying to use the Not in List event of a combo box to both add the new
data to the control's rowsource and also to a table that consists of only
two fields, one of which is an autonumber primary key.

But everytime I run it I get a message box:  Enter Parameter Value, with the
value of the combo box listed with a text box to enter into.  I just hit
okay, it updated the value list, said it was appending a record, then said
it couldn't do it due to it creating a key violation.
How can it create a key violation if I am inserting new data?

I'm sure I'm overlooking something simple but its driving me crazy, more
than usual anyway.

Thanks,
Nancy L

CODE Currently being used:

Private Sub cboTechLead_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
    ' Return Control object that points to combo box.
    Set ctl = Me!cboTechLead

    ' Prompt user to verify they wish to add new value.
    If MsgBox("Value is not in list. Add it?", _
         vbOKCancel) = vbOK Then
        ' Set Response argument to indicate that data
        ' is being added.

    	  Response = acDataErrAdded
        ctl.RowSource = ctl.RowSource & ";" & NewData
        DoCmd.RunSQL "insert into lkptbTechLead([Tech Lead]) values (" &
NewData & ")"
    Else
    ' If user chooses Cancel, suppress error message
    ' and undo changes.
        Response = acDataErrContinue
        ctl.Undo
    End If

End Sub



More information about the AccessD mailing list