open subform with command button

  • Thread starter Thread starter Bubba
  • Start date Start date
B

Bubba

Is it possible to have subforms that open with command
buttons from the main form? If so what is required to
verify that the subform's data is linked to the record in
the main form?
Thank You,
Bubba
 
Bubba,

All you need is a line of code something like:

DoCmd.OpenForm "FormName",,,"JointControl2=" & Me.JointControl1

The last part of the expression is a filter that secures you only get
records related to the current record in the main form. Change:
FormName > the name of your subform
JointControl1 > the name of the control on the main form holding the field
joining the two tables
JointControl2 > the name of the control on the subform holding the field
joining the two tables

HTH,
Nikos
 
I put the code in as you specified substituting my names
and the form opens but is not linking to the main form.
FormName:frmPlantingDetails(subform)
JointControl1:PlantingID(primary key on frmPlantings)
JointControl2:PlantingID(foreign key on frmPlantingDetails)
When the form opens the PlantingID field shows "0" instead
of the PlantingID number on the main form.
Thanks
 
Back
Top