Erro 3201

G

Guest

I get the following error w/ the code below. Can someone help me with
figuring out how to insert the current VisitNo (fldVisitNo) that is linked to
RNnotes into the equation below. Thanks Robert

Error 3201 You cannot add or change a record because a related record is
required in table "tblVisit."


Dim db As DAO.Database
Dim strSQL As String
Dim varItm As Variant

Set db = CurrentDb()
With Forms!frmRNnotes!lstRNnotesLU
For Each varItm In .ItemsSelected
CurrentDb.Execute ("INSERT INTO tblRNnotes (fldRNnotes) " _
& "VALUES ('" & .ItemData(varItm) & "');"), dbFailOnError
Next varItm
End With

Debug.Print
 
G

Guest

When you are inserting records into a child table, you have to include the
foreign key to the parent record (the field that relates the child to the
parent). Add that to your SQL.
 
G

Guest

Since I don't know the name of the control where the Parent primary key is or
what it's name is, I can't give the exact names, so below is only an example

CurrentDb.Execute ("INSERT INTO tblRNnotes (fldRNnotes, fldForeignKey) " _
& "VALUES ('" & .ItemData(varItm) & ", " & .txtParentPrimary Key & "');"),
dbFailOnError
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top