Add code to not in list event

I have this code in a not in list event of a combobox.

Private Sub cboType_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_cboType_NotInList

    Dim intAnswer As Integer
    Dim strSQL As String
    
    intAnswer = MsgBox(NewData & " is not in the list. Would you like to add it?", vbQuestion + vbYesNo, "Description")

    If intAnswer = vbYes Then
        strSQL = "INSERT INTO tblTypesLU([Description]) " & "VALUES ('" & NewData & "');"
        CurrentDb.Execute strSQL, dbSeeChanges
        Response = acDataErrAdded
    End If

Exit_cboType_NotInList:
    Exit Sub

Err_cboType_NotInList:
    MsgBox "Error Number: " & Err.Number & vbCrLf & "Error Description: " & Err.Description & vbCrLf & "Error Source: " & Err.Source
    Resume Exit_cboType_NotInList

End Sub

Open in new window


But I want to add the DetailID from the form to the syntax.

So if the table looks like this prior to the code:

RecordID         Description          DetailID
1                       Something  
2                       Something Else

Have it look like this after the code runs:

RecordID         Description          DetailID
1                       Something               47
2                       Something Else       47

How would I change the on not in list event?
SteveL13Asked:
Who is Participating?
 
John TsioumprisConnect With a Mentor Software & Systems EngineerCommented:
strSQL = "INSERT INTO tblTypesLU([Description],[DetailID]) " & "VALUES ('" & NewData & "','" & Me.DetailID &"'");"

Open in new window

0
 
PatHartmanCommented:
The simple answer is to modify the insert to add the second field but in reality, I have no clue what you are trying to do.  What would the purpose of adding the ID of the first record to which the lookup value was attached to the lookup table?
0
 
SteveL13Author Commented:
Pat, the purposes it to add the ID so that further forms cannot not use it.  Only the original one.
0
 
PatHartmanCommented:
That would make this a 1-1 relationship.  Those are extremely rare in the wild and would not be implemented using a combo.  The combo implies 1-many.  But, you have accepted an answer so whether I understand what you are doing or not is immaterial.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.