Full Version: Set Parent Form Field To Sub Form Field
UtterAccess Forums > Microsoft® Access > Access Forms
sforney123
Running Access 2007 and I have a form called Main with a Combobox called Station. I have a sub form (inside the main form) called Insp Sub with a field called Station. I would like to set an After Update event on the Main Form when someone changes the Station Combobox to have the Insp Sub showing the records that match the Station Combobox on the Main Form. Right now I have the DoCmd.OpenForm function working but I'd like the sub form to update automatically inside the Main form without having a new window open. I have set the Link Master Fields to Station and the Link Child Fields to Station but this doens't do the trick.
Below is the code I have for the Do.Cmd Open Form.
Private Sub Combo2_AfterUpdate()
DoCmd.OpenForm "Insp Sub", acNormal, "", "[Insp Data].[Station1]=[Forms].[Main].[Combo2]", acAdd, acNormal
End Sub
Insp Data is the table that feeds Insp Sub.
MikeLyons
Reading your code and description I think there might be some confusion going on -- is the combobox named Station or Combo2 ?
nd, in the subform, is the FK that relates to the parent record called Station or Station1 ?
You need to make sure the LinkMasterFields property indicates the actual name of the control on the main form, and that the LinkChildFields property indicates the actual name of the field in the subform's recordset (even if you don't include a control for that field on the subform itself).
Mike
MiltonPurdy
Did you set your parent-child link to make the subform go to the same record as the mainform?
On a mainform-subform setup, you need a one-to-many relationship. One side is the mainform, many side is the subform, then the two should link automatically.
You need the primary key of the one table to be the foreign key of the many.
sforney123
Sorry for the confusion... Dropping the name Control source into the Link Master seemed to do the trick along with setting the One to many relationships. Thank you!
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.