Here is the code I have in my NotInList event
Private Sub ClockNo_NotInList(NewData As String, Response As Integer)
Dim cn As Connection
Dim rs As ADODB.Recordset
If MsgBox(NewData & " is not in the selection provided. Would you like to add it?", vbQuestion + vbYesNo, "Unknown Course") = vbYes Then
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
With rs
.Open "Supervisor", cn, adOpenStatic, adLockPessimistic
.AddNew
.Fields("ClockNo") = StrConv(NewData, vbProperCase)
.Update
.Close
End With
Response = acDataErrAdded
Else
Me.ClockNo.Undo
Response = acDataErrContinue
End If
Set rs = Nothing
Set db = Nothing
End Sub
My error message pops up, then a Microsoft error message pops up and says you must choose data from the list and when I click ok it sticks me back into that field. So then when I try to enter the same thing again I get an error that says I am trying to enter data that is already in the table. How can I get the Microsoft message not to pop up? Also do you see anything wrong with my code?
Private Sub ClockNo_NotInList(NewData As String, Response As Integer)
Dim cn As Connection
Dim rs As ADODB.Recordset
If MsgBox(NewData & " is not in the selection provided. Would you like to add it?", vbQuestion + vbYesNo, "Unknown Course") = vbYes Then
Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
With rs
.Open "Supervisor", cn, adOpenStatic, adLockPessimistic
.AddNew
.Fields("ClockNo") = StrConv(NewData, vbProperCase)
.Update
.Close
End With
Response = acDataErrAdded
Else
Me.ClockNo.Undo
Response = acDataErrContinue
End If
Set rs = Nothing
Set db = Nothing
End Sub
My error message pops up, then a Microsoft error message pops up and says you must choose data from the list and when I click ok it sticks me back into that field. So then when I try to enter the same thing again I get an error that says I am trying to enter data that is already in the table. How can I get the Microsoft message not to pop up? Also do you see anything wrong with my code?