JeffreyDavid
Registered User.
- Local time
- Today, 12:45
- Joined
- Dec 23, 2003
- Messages
- 63
I have a combo box based on a Table/Query. I want to add an item to the existing list so next time the form is open, the new item will be available from the list. I have added the following code to the NotInList event but keep getting an error message saying 'The text you entered isn't an item in the list. Select an item from the list, or enter text that matches one of the listed items.' I have the LimitToList = yes My NotInList event code is:
Private Sub cmbDescription_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available description Name" & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new description to the current Table?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrAdded
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("SalesProduct", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!DESCRIP = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Can anyone see why this wouldn't work?
Private Sub cmbDescription_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available description Name" & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to associate the new description to the current Table?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrAdded
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("SalesProduct", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!DESCRIP = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
Can anyone see why this wouldn't work?