So I have some code I use to add values to a combo box when they are not allready there.
But I cant seem to get it to work when its a Many to Many setup, I want to add a new COI, it will ask if I want to add it and the code will run. But after its done it errors with, value not in list.
I think it has to do with refreshing the data but I cant seem to wrap my head around it.
Code:
Private Sub cboCOI_NotInList(NewData As String, Response As Integer)
Response = fNotInList(NewData, "tblQSCOI", "QSCOI")
End Sub
Code:
Function fNotInList(NewValue, strRecordSource As String, strFieldName As String)
10 If MsgBox("The value '" & NewValue & "' does not exist, do you want to add it?", vbQuestion + vbYesNo) = vbYes Then
'proceed
15 DoCmd.SetWarnings False
20 DoCmd.RunSQL "INSERT INTO [" & strRecordSource & "] ([" & strFieldName & "]) SELECT '" & NewValue & "'"
30 fNotInList = acDataErrAdded
Else
40 fNotInList = acDataErrContinue
End If
But I cant seem to get it to work when its a Many to Many setup, I want to add a new COI, it will ask if I want to add it and the code will run. But after its done it errors with, value not in list.
I think it has to do with refreshing the data but I cant seem to wrap my head around it.