dynamic subform name

D

Danny Nielsen

Hi
I have a form and in this a subform. I want this subform to change during
runtime. Therefore I changes its sourceobject property. No problem so far.
What I further want is to call methods on this subform but because I dont
know its name before runtime (not static) I dont know how to call it!
Normal, you would use

me.subformname.forms.control

but in my case subformname is not a variable, but a string representation.
If it was a form I would use forms("formname string"). Is this kind of
possible with subforms too (and if .. how?)

Thanks in regards

Danny
 
N

Neil

Hello Danny,

I dont really get your question here. If you have a sub form control on your
form say "subFrmCtl", you will always use this name when getting the methods
and properties for this control. If you want to get to the recordset of the
sub form you would always write Me.subFrmCtl.Form.RecordsetClone. You are
only changing the SourceObject property of the sub form control when
changing forms. I suppose you can get to the form by writing
Forms(Me.subFrmCtl.SourceObject).SomeControl but this would just generate an
error as the form isn't open. A little tip on this is to get the subform to
do all the error checking and any data manipulation from it's own events for
itself and dont rely on the main form to do the work on all the subforms
(hope that made sense).


Neil.
 
W

Wayne Gillespie

Hi
I have a form and in this a subform. I want this subform to change during
runtime. Therefore I changes its sourceobject property. No problem so far.
What I further want is to call methods on this subform but because I dont
know its name before runtime (not static) I dont know how to call it!
Normal, you would use

me.subformname.forms.control

but in my case subformname is not a variable, but a string representation.
If it was a form I would use forms("formname string"). Is this kind of
possible with subforms too (and if .. how?)

Thanks in regards

Danny

Changing the SourceObject of a subform does not change the name of the subform
control it is contained within. So you only really need to know the name of the
control on the subform itself you want to reference.

Assuming the name of your subform control is "frmMySubForm" then you will always
refer to a control on the subform as -

Me.frmMySubForm.Form!NameOfControlOnSubform

As long as "NameOfControlOnSubform" is a valid control on the subform that is
currently the SourceObject of the subform control, you should have no problems.

eg:
Me.frmMySubForm.SourceObject = "frmSubForm1"
X= Me.frmMySubForm.Form!NameOfControlOnSubform1

Me.frmMySubForm.SourceObject = "frmSubForm2"
Y= Me.frmMySubForm.Form!NameOfControlOnSubform2

Wayne Gillespie
Gosford NSW Australia
 
D

Danny Nielsen

hi
have gone it up and running. Sorry my bad English but I were in a hurry.
Thanks for your answers.

Danny
Denmark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top