Greetings,
I have a basic table, CourseNameT which looks like this:
In the corresponding form, I have txtCourseID, cboCourseName, cboType (can only be either External or Internal), and txtValidFor. I am trying to use NotInList event so that user can add new courses if it doesn't already exists (the check and balance comes from BeforeUpdate even where if combo of CourseID and Type exists, user won't be allowed to proceed with new entry). Following is the simple code I have for this purpose:
The issue I am having can be best shown via images, as below:
Upon pressing Yes, I get following:
As you can see, there is now an additional record, CourseID 78, with the same name as the one I entered i.e., CourseID 77. Any idea why this might be happening?
Thanks to all in advance.
I have a basic table, CourseNameT which looks like this:
In the corresponding form, I have txtCourseID, cboCourseName, cboType (can only be either External or Internal), and txtValidFor. I am trying to use NotInList event so that user can add new courses if it doesn't already exists (the check and balance comes from BeforeUpdate even where if combo of CourseID and Type exists, user won't be allowed to proceed with new entry). Following is the simple code I have for this purpose:
Code:
Private Sub cboCourseName_NotInList(NewData As String, Response As Integer)
Dim strTmp As String
' get confirmation
strTmp = "'" & NewData & "' does not exist in the database." & vbCrLf & "Would you like to add '" & NewData & "' as a new course?"
If MsgBox(strTmp, vbYesNo + vbDefaultButton2 + vbQuestion, "Add new course?") = vbYes Then
' Append the NewData as a record in the CourseNameT
strTmp = "INSERT INTO CourseNameT ( CourseName ) " & _
"SELECT """ & NewData & """ AS CourseName;"
CurrentDb.Execute strTmp
Me.cboCourseName.Requery
Response = acDataErrAdded
Else
Me.Undo
End If
End Sub
The issue I am having can be best shown via images, as below:
Upon pressing Yes, I get following:
As you can see, there is now an additional record, CourseID 78, with the same name as the one I entered i.e., CourseID 77. Any idea why this might be happening?
Thanks to all in advance.