Referencing a control on a Subform

  • Thread starter Thread starter Lee
  • Start date Start date
L

Lee

Good morning all,

I have a Search form where you can double-click on a
returned record to 'jump' to a specific record within
another form (that's always open).

My problem is that I can jump to the overall record that is
on the main form but I'd really like to be able to jump to
a specific record within a Subform. I've tried various
syntax to get this to work without success.

Supposing the forms/controls have the following names, can
you advise how I should refer to the record within the
Subform?

Search form = frmSearch
Control to match record on = ID
Main form = frmMain
Subform = frmMainSub
Control to match record on = SubID

I hope you can help!

Regards,

Lee
 
A subform is not open by itself - it is only open indirectly through the
subform control on the main form. So a normal reference a control on the
subform, you must also reference the subform control. If the subform control
is named frmMainSub and the control on the subform is named SubID then from
the class module of the main form the correct reference to this control
would be:

'to assign a value using code in the main form:
me.frmMainSub.form.SubID=123

'to assign a value using code in any module
forms!frmMain.frmMainSub.form.SubID=123

Note that 'frmMainSub' must be the name of the subform control on the main
form. This is not necessarily the same as the name of the form object that
is referenced in the ControlSource of the subform control. To be sure, open
the main form and click once on the subform then check the name property
under the Other tab. Whatever you find there is what belongs in place of
frmMainSub.

Now to make a specific record in the subform the current record, you would
probably want to use the Recordsetclone of the subform:

with forms!frmMain.frmMainSub.form.recordsetclone
.findfirst "Subid=" & me.ID
if not .nomatch then
forms!frmMain.frmMainSub.form.bookmark=.bookmark
endif
end with
 
Many thanks for your help. With yours and Sandra's help
it's all fine now!

Much appreciated.

Lee
 
Back
Top