Many-to-many data entry form / subformat

I have an Access database with many-to-many relationships. 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 several of its own objects. I created a join table to host these MM relationships.

Here is the location of the relationship: enter image description here

To populate these tables, I created a form for the property with a subform for the Person table. I have completed several articles and posts to implement the necessary functions. They are here , here , here and here .

Here is the form: enter image description here

PersonName is a combo box in which its row source is given by the following SQL query:

SELECT Person.idPerson, Person.PersonName FROM Person; 

The number of columns is set to 2, and the width is set to 0 cm, 1 cm

The VBA code I used for the NoInList event in the combo box:

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 works fine, but I came across the case when two people have the same name. The form will not allow this, as every time you enter a name that is already in the table, you probably get the existing values ​​associated with this person. Creating a new record in the Person table makes this record visible in the combo box of the form, but I do not want the data entry user to edit the tables.

How can I implement the functionality to create a new record in the Person table from the form and ask the user to confirm the new record?

P.S. , , .

: , . , , .

+4
1

- . , , , [_], , .

. .

0

Source: https://habr.com/ru/post/1667503/


All Articles