Hi All,
After reading many threads in this most valuable forum, I tried to set up a combobox in my form to automatically add a value that a user puts. It's not quite working.
I have my LimitToList property set to Yes and have added the code below to the NotInList event.
However, when I try to run it, I get an error that says the CategoryID must not be empty (referential integrity that is required in this table). The thing is, I have already entered the CategoryID before getting to the combobox in question.
Do I need to somehow update the DB before starting the code below? Or what...
Thanks as always!
Private Sub cmboIssueName_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
If vbNo = MsgBox("Would you like to add a new issue?", vbQuestion + vbYesNo, "Add Issue?") Then
Response = acDataErrContinue
Exit Sub
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblIssue", dbOpenDynaset)
rs.AddNew
rs!IssueName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub
After reading many threads in this most valuable forum, I tried to set up a combobox in my form to automatically add a value that a user puts. It's not quite working.
I have my LimitToList property set to Yes and have added the code below to the NotInList event.
However, when I try to run it, I get an error that says the CategoryID must not be empty (referential integrity that is required in this table). The thing is, I have already entered the CategoryID before getting to the combobox in question.
Do I need to somehow update the DB before starting the code below? Or what...
Thanks as always!
Private Sub cmboIssueName_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
If vbNo = MsgBox("Would you like to add a new issue?", vbQuestion + vbYesNo, "Add Issue?") Then
Response = acDataErrContinue
Exit Sub
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("tblIssue", dbOpenDynaset)
rs.AddNew
rs!IssueName = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End If
End Sub