linked vs. subform (1 Viewer)

dhoffman

Registered User.
Local time
Today, 16:39
Joined
Jul 11, 2000
Messages
69
I was using Access's wizard to create a form based on two tables with a one to many relationship. I want the subform to be linked rather than exist on the parent form as a subform. The wizard provides this option. However, when I add some records to the linked form, the field that is the link to the parent form is not updated automatically as with a subform existing on the parent form. Do you understand what I'm trying to say? See, I don't want the field that links the two tables to appear on the child form. So I need it to be automatically updated with whatever the curent value of that field is on the parent form. If you use subforms this is done automatically, but does not seem to be taken care of if you use linked forms. Am I supposed to add some code of my own to accomplish this? I would have expected the wizard to take care of it. I don't think I did anything wrong, but perhaps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:39
Joined
Feb 19, 2002
Messages
43,377
I don't usually build this type of form with the wizard so I'm not sure what it does and does not do. Although for what it's worth, I think it should have taken care of the keyfield also.

In any event, in the BeforeUpdate event of the linked form, put the code to populate the key field.

Me.Keyfield = Forms!YourMainForm!YourKeyfield

I use this event so that I don't dirty the form just by entering it which is what would happen if you put the code in a different event. The BeforeUpdate event only fires if the user has made an update that needs to be saved and it will fire no matter how the form is closed.
 

dhoffman

Registered User.
Local time
Today, 16:39
Joined
Jul 11, 2000
Messages
69
well, I actually did almost the same thing already, but I used the AfterUpdate event. I had tried using BeforeUpdate but I had some problem with not being able to get the cursor to leave the record (go to the next record.) Maybe I had some other problem that caused this but AfterUpdate seems to be working. Will AfterUpdate have any different undesirable results?
 

dhoffman

Registered User.
Local time
Today, 16:39
Joined
Jul 11, 2000
Messages
69
nevermind, it was AfterUpdate that was screwing me up. You were right, BeforeUpdate works perfectly.
 

Users who are viewing this thread

Top Bottom