Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2006, 03:31 AM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Main/Subform linkage

Hi all,

Probably a simple problem, but thus far I've not been able to solve it.

I have a main form with a sub form; the subform is linked to the main form by an automaticly generated number as the subforms PK.

I can view and edit data perfectly, however when I try and add a new record to the sub form I get a message telling me that the field CAD_ID (subforms pk) is read only. Thus is will add a record to the sub form, but not link it back to the main form.

I'm wondering if the auto generated number is causing a problem somehow?

I'd be most gratefll for any ideas!

Cheers,

Ben.

 
Old April 5th, 2006, 07:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It might be me, but it sounds like you have the association backwards. Shouldn't you link the subform to the main form based on the main form's PK, not the subform's PK. It should be the subform's FK to the main form's PK.

HTH

mmcdonal
 
Old April 5th, 2006, 11:28 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm not sure if that's it mmcdonal. If there's a 1:1 relationship, then using the autonumber as the PK for the subform data and having it a FK in the main form data would work fine.

Ben, are you trying to enter new data by overwriting the data in the subform, or by advancing to a blank record (>* button) and adding it there? The problem with using the autonumber as the FK in the main form's data means you can only link 1 subform entry to a given main form entry. If you need more than 1 subform entry to a main form entry, you'll need to pick a different FK for the main form's data.

 
Old April 5th, 2006, 11:33 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

There is rarely a 1:1 relationship. It is almost always 1:Many, so changing the parent and child fields to the standard (PK on parent) would resolve this problem, without more information.



mmcdonal
 
Old April 5th, 2006, 01:07 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Default

True, but it also works for a many:1 (i.e. a part browsing form, with the vendor info in a subform).






Similar Threads
Thread Thread Starter Forum Replies Last Post
Synchronizing main form w/subform (i.e. backward) paladin Access VBA 7 April 19th, 2007 06:40 AM
Moving total from Subform to Main Form Shepwad Access 1 March 10th, 2006 10:57 AM
updating main form from subform dartcoach Access 6 April 28th, 2005 08:27 AM
Filter Subform B Based on Field in Subform A SerranoG Access VBA 3 June 18th, 2004 12:23 AM
Filter subform from main form DBoulos Access VBA 2 October 30th, 2003 12:20 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.