How add record into a table that is joined to another in many-to-one?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to add a child record using VB event code. It's simple in datasheet mode - all I have to do is put the data into the child fileds of a new row. As soon as I put a the parent's id into the child's llnk field, the row expands to the right to show the fields in the parent record (e.g., the joined row)

In VB, I create a new row using DoCmd.GoToRecord , , acNewRec. I populate the fields with data, including the child field that links me to the parent, then exit

When I try to add another child (by creating a new row), I get error message saying that I cannot add the new record (the previous one, I assume) because it would create a duplicate parent record. I don't want to create a new parent, I just want to link the new child to an existing parent. I've tried several save/update commands that don't work. What code should I use in VB so that my child record is created linked to it's pre-existing parent

If you post a reply in this forum, please send me e-mail to let me know. Thx!
 
What code should I use in VB so that my child record is created linked to it's pre-existing parent?

I'd suggest using an Append query to add the child record *to the
table*, rather than trying to add it via the Form. You can pick up the
Primary Key value of the currently selected mainform record directly
from the form - you will probably need to save the record to disk
first using

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty = True Then Me.Dirty = False
 
Back
Top