Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2006, 03:31 AM
Registered User
 
Join Date: Apr 2006
Location: , Scotland, United Kingdom.
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.

Reply With Quote
  #2 (permalink)  
Old April 5th, 2006, 07:12 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
Old April 5th, 2006, 11:28 AM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
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.

Reply With Quote
  #4 (permalink)  
Old April 5th, 2006, 11:33 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #5 (permalink)  
Old April 5th, 2006, 01:07 PM
Friend of Wrox
 
Join Date: Dec 2005
Location: , , .
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).

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:35 PM.


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