subform problem

B

Bonnie

I have a form with two subforms on it. They are linked on the OrderNo field.
The problem is adding a new record (I have it set to Data Entry) - when I go
to the subform and first click on the option I get the message:

"The current field must match the join key '?' in the table that serves as
the 'one' side of one-to-many relationship."

It then directs me to create a record that matches first and then make the
entry. I tried using DOCMD.GoToRecord to create a new record without
success. Once I get it to accept the record and stop giving me messages, I'm
good. Oh, I also tried requery, gotocontrol onload, etc.

Any idea how to smooth this out?

Thanks in advance,

Bonnie
 
P

Pat Hartman

You CANNOT create a subform record without first creating a parent record.

Your subform should check the autonumber field of the parent table for null.
If the parent's ID is null, then the subform should set focus to the first
field in the parent form and display a message.
 
B

Bonnie

Yes, I should have mentioned that I did create a parent record first
(although I will take your suggestion to check and return focus to the
parent). Do you know what could be causing me to get this error still, even
after creating a parent record. I even put a save button and save the parent
record, though I know I shouldn't have to. I have check the link information
multiple times and it is showing OrderNo (and that was the suggested).

Any help is appreciated.

Thanks,

Bonnie
 
P

Pat Hartman

check the master/child link fields to make sure they contain the appropriate
reference to the parent's primary key and the child's foreign key fields.
 
B

Bonnie

Thanks for responding Pat.

I did check that, as a matter of fact, I accepted the suggested link
information of orderno (which is what I wanted it to be anyway). Something
really funky going on with it but I have started from scratch and redone the
form and got it to work now.

Thanks.
 
C

cgwhites

I was having the same problem and found the solution after much fiddling:

Make sure that the subform contains the field that is being used as the
link. For example, if the master/child forms are linked on Customer_ID, and
you don't need to see Customer_ID in the subform, add it anyway and make it
invisible. This will allow the creation of the record on the "many" side of
the relationship to be created without this seemingly pointless error.

Chris
 
B

Bonnie

Thanks Chris - that wasn't my problem (I had the field on the subform and
form) but I fixed it anyway. Sometimes you don't find out what the problem
is but moving on is what matters. Thanks for your interest though.
 
Top