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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autopopulate Foriegn key not working!

Status
Not open for further replies.

kc112

Technical User
May 16, 2011
41
US
I have a main form with a autopopulated primary key titled "key". I then created a second table and form (my subform) with a field entry entitled "key" for a foriegn key. (I did not set a primary key on my subform)

I opened up the relationships and linked both tables with a bold line via "key",

I created my main form and it shows my autopopulated primary key, Then I added a subform with the field "key". On the properties on the subform, under the data tab, I linked parent/child master levels with "key".

But it does not autopopulate the primary key into the foriegn key on the subform?! If I manually type the key into the "key" field on the subform, it links fine, but I don't want the user error of having to type it in manually becuase I plan on having multiple subforms in use. I would like it to autopopulate the foriegn key.

Where did I go wrong?

p.s. Thanks to all that helped me on my last problem, I was able to solve everything! :0)
 
So both forms are bound I trust.... Sounds like you did everything right but I think that key may be a keyword and therefore Access is getting confused. Try putting square brackets around it in master and chinld fields (and everywhere else you use the field for that matter)....

Code:
[key]
 
Yes, thank you for the advice. I will either change my field name or put [] brackets.

Also, I was wrong! I correctly linked parent/child forms when I added a subreport to my report. But when I did it on the form, I only added a button wih an docmd. openform prompt. This only opens a parallel form NOT a subform.

I ended up adding to the default value portion under the properties tab, something like: key!treatmentplandata!key. Now, it pulls the PK from the [key] field on the main form to the FK [key] field on the subform.

I still have it linked via a relationship, so after a long restfull weekend, I hope to return to work on tuesday and make sure it works properly! :0)


 
So you don't have a subform.... you may need to add criteria to your docmd.openform statement so it opens with a filter.

Code:
docmd.OpenForm "FormName", acNormal,,"Key = " & Me!Key
 
How are ya kc112 . . .
kc112 said:
[blue]But it does not autopopulate the primary key into the foriegn key on the subform?![/blue]
The key to your resolve lies in your quote above. Are you saying the [blue]Key[/blue] for previously saved records in the subform do not show up or what?

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top