DblDogDare
Technical User
I am having some difficuly with this NotInList event. My problem is; I am entering the new resource, then I tab to the next field. I get the message box to add the new resource. I enter the new resource and the name is added as a record in the table, but not in the list of the Combo Box and it keeps asking me to enter it again, so I have multiple entries of the same resource in the table. I have noticed that if I pick "No" the second time, it shows the new resource in the combo Box list. I think it is a problem with the requery of the combobox. Here is my code, please if someone can help, it would be greatly appreciated.
Private Sub cboResource_NotInList(NewData As String, Response As Integer)
vResponse = MsgBox("Data entered '" & NewData & "' is not contained in current list." & Chr(13) & "Do you wish to add it to the file?", 36, "New Data Prompt")
If vResponse = 6 Then
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Set MyDB = CurrentDB
Set MyRS = MyDB.OpenRecordset("tblResources", dbOpenDynaset)
MyRS.AddNew
MyRS("DataField1") = NewData
MyRS("LastName") = Trim(Mid$(NewData,1,Instr(1,NewData,",")-1))
MyRS("FirstName") = Trim(Mid$(NewData, Instr(1,NewData,",")+1))
MyRS.Update
MyRS.Close
MyDB.Close
Response = DATA_ERRADDED
Else
Me![cboResource] = Null
Response = DATA_ERRCONTINUE
Me.cboResource.Requery
End If
End If
End Sub
Private Sub cboResource_NotInList(NewData As String, Response As Integer)
vResponse = MsgBox("Data entered '" & NewData & "' is not contained in current list." & Chr(13) & "Do you wish to add it to the file?", 36, "New Data Prompt")
If vResponse = 6 Then
Dim MyDB As DAO.Database
Dim MyRS As DAO.Recordset
Set MyDB = CurrentDB
Set MyRS = MyDB.OpenRecordset("tblResources", dbOpenDynaset)
MyRS.AddNew
MyRS("DataField1") = NewData
MyRS("LastName") = Trim(Mid$(NewData,1,Instr(1,NewData,",")-1))
MyRS("FirstName") = Trim(Mid$(NewData, Instr(1,NewData,",")+1))
MyRS.Update
MyRS.Close
MyDB.Close
Response = DATA_ERRADDED
Else
Me![cboResource] = Null
Response = DATA_ERRCONTINUE
Me.cboResource.Requery
End If
End If
End Sub