Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add record to subform - loss of LinkChild/Master Fields Property

Status
Not open for further replies.

aaronino

Programmer
Aug 6, 2001
19
US
I figure this must be a common problem, but I haven't found any information on it in the forums.

I have a standard form/subform setup, where my subform displays each of the many records found for the current record found on the primary form. The relationship is defined in the Relationship window (1-Many). The subform displays records in a continuous form view. When I load the form and navigate through the records, there are no problems - but when I add a record to the subform, it displays all of the records from the subforms datasource, instead of just the related records.

I have extensively tried to refresh the subform from methods on both the parent form and the subform itself, but this doesn't work. The only method I've found that "sort of" works is to reset the linkchildfields and linkmasterfields properties, but this also causes problems. I display information about the the current record selected on the subform using the parent form, and when I reset the linkchildfields and linkmasterfields properties, the information is incorrect -- it displays information about the wrong record in the subform.

Two other things to note is that technically, the linkchildfields and linkmasterfields properties never change. If I don't reset them after adding a record, they are still both set to exactly what they should be (Primary Key of parent, Foreign Key of subform). Second, if I take the form into design view and then back into form view, there aren't any problems.

Anyone have any ideas? Help would be much appreciated.
 
Hi,

I can't duplicate your problem, but a colleague told me about this....

On your subform, (if it's not already there) paint a text box for the foreign key field of your 'many' table (obviously hide it), set it's 'default value' property to the 'main' form primary key value to 'force' population of the fk.

If this works, then obviously Access is 'losing' the relationship between the one and many for some reason.

I have noticed sometimes that even though the form datasource is set to retrieve specific fields, if they are not 'physically' painted on the form there can be problems.

Hope it helps.

Regards,

Darrylle

"Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Hi Darrylle,

I've noticed the same thing -- leaving the key value off of a subform can cause problems.

But unfortunately, I don't think that's the problem this time. I've tried binding a text box to the Parent Forms Primary Key with no luck. In fact, every time I add a record I reset the value of the text box, but still not having any luck.

I think I'm just going to rewrite the same form -- it's probably just some quirky thing that'll be fixed by remaking the forms.

Thanks anyway!

aaron
 
Hiya,

An idea or 2....

a) Most importantly - when I add a record to a subform, I leave the final field and nothing happens - why does your subform suddenly do a requery (to display all unrelated records)?
You aren't requerying after update are you? You need do nothing - the relationship handles this.

b)You have stated above that you have 'extensively'
refreshed the subform.
With 'parent' / 'child' forms you should refresh the 'parent' form only (which you probably have tried, but I thought I'd point it out).

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top