By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,154 Members | 2,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,154 IT Pros & Developers. It's quick & easy.

.AddNew does not work if a relationship is declared.

P: n/a
The following code copies recordset rs into recordet rst and adds it
to tblVMSParts. The records being copied are the data that shows on a
subform. I copy all of the data from the main record, create a new
record, paste it all in with a new key and then create the subform
records with the new key ([VMS]). This works perfectly if I have no
relationship declared between the parent table and the child table.
As soon as I set up the relationship the subform records no longer get
copied over. Stepping through the code it seems to work but the new
records are not created.

I am completely stumped.

rs.MoveFirst
Do Until rs.EOF
With rst
.AddNew
![VMS] = strVMS
![Quantity] = rs![Quantity]
![Description] = rs![Description]
![PartNum] = rs![PartNum]
![Torque] = rs![Torque]
.Update
End With
rs.MoveNext
Loop

rs.Close
Set rst = Nothing

rst.Close
Set rst = Nothing

Thanks,

Bill
Newtown, PA
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Bill,
are you including the Foreign key in your child table? If not,
referential integrity constraints are disallowing your add.
Essentially, what this means is, if you do not add a Foreign Key value
that is in the domain of foreign key (in your parent table), then the
insert will ALWAYS fail. So you have to add something like:

rs.Fields("ForeignKeyFieldName")= ...' some legal value

and then you should be fine.

HTH,
Pieter
Nov 12 '05 #2

P: n/a
Thanks for the reply. In my code you can see

With rst
.AddNew
![VMS] = strVMS

![VMS]is the foreign key from the child. The 5 fields I am updating are
the only 5 fields in the table. I was wrong in my first posting, this
works when I have the relationship defined but does not work when I turn
on referential integrity.
Thanks,

Bill
Newtown, PA

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.