I have an Access database with a many-to-many relation. The origin table is called Property and the destination table is called Person. A property can have more than one owner, and a person can own more than one property. I created a join table to accommodate this M-M relationship.
Here is the relationship layout:
In order to fill these tables, I created a form for Property with a subform for the Person table. I followed several articles and posts to implement the needed functionality. They are here, here, here and here.
The PersonName is a combo box with its row source set to the following SQL query:
SELECT Person.idPerson, Person.PersonName FROM Person;
The column count is set to 2 and the width is set to 0cm;1cm
The VBA code I used for the NoInList event of the combo box is:
Private Sub PersonName_NotInList(NewData As String, Response As Integer)
strSQL = "INSERT INTO Person([PersonName]) " & _
"VALUES ('" & NewData & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new person has been added to the list." _
, vbInformation, "Data Entry"
Response = acDataErrAdded
End Sub
Everything is working fine so far but I'm faced with the case where two persons have the same name. The form won't allow this as every time you type a name that is already in the table, predictably you get the existing values associated with this person. Creating a new entry in the Person table makes this entry visible in the form's combo box, but I don't want the data entry user to edit the tables.
How can I implement the functionality to create a new entry in the Person table from the form, while asking the user to confirm the new entry?
P.S. I know the question title doesn't specifically reflect the content, but I couldn't find a better wording for it.
Edit: To keep the question simple, I trimmed down the fields in the tables. There are additional attributes like date of birth that can possibly differentiate between two persons with the same name.