By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

Referencing a control on a subform

P: n/a
Mat
Dear all,

What I want to do is be able to use a string to refer to a control on a
subform.

IE:

Forms!("Form1!form2!controlA").name

or

Forms(txtControlPath).name

Neither of which work (or I am not using correctly).

Help appreciated.

Thanks,

Mat

May 4 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ray
Forms!MainFormName!subFormControlName.form("YourSt ring")

Ray

May 4 '06 #2

P: n/a
ray
Forms!MainFormName!subFormControlName.form("YourSt ring")

Ray

May 4 '06 #3

P: n/a
Mat
Thanks Ray,

However the issue is that with the way you are specifying it I still
have to hardcode the first part.

ie: Forms!MainFormName!subFormControlName.form

I really would like to refer to the whole path to the control I then
want to access methods and properties of.

May 4 '06 #4

P: n/a
"Mat" <ma*********@optusnet.com.au> wrote in news:1146725486.556444.319570
@i39g2000cwa.googlegroups.com:
Dear all,

What I want to do is be able to use a string to refer to a control on a
subform.

IE:

Forms!("Form1!form2!controlA").name

or

Forms(txtControlPath).name

Neither of which work (or I am not using correctly).

Help appreciated.

Thanks,

Mat


Check the HasModule Property of the SubForm. It should be set to Yes. (In
Access 97 just be sure the SubForm has some code.)

Then

Form_NameofSubForm.Property

and

Form_NameofSubForm.Method

should work well.

--
Lyle Fairfield
May 4 '06 #5

P: n/a
Mat
Lyle I dont think that's what I want.

I am asking whether I can use a variable to reference a control on a
subform?

Suppose you have two forms Form1 and Form2 with a control on each Text1
and Text2 and form2 is a subform of form1.

I can refer to the forms and controls in code from the immediate window
by hardcoding either:

forms!form1!form2!Text2

or

forms("form1")("form2")("text2") (this is close
to what I want but would require that I always had only one level of
depth to my subforms to work.)

ideally i want to be able to have a string variable access the control
on any subform.

forms("form1!form2!text2")

or

forms(strVariabletoControlOnAnyFormOrSubForm)

my question is whether this is possible and if so how can i do it?
Perhaps I do not use the forms collection at all?

Thank you for your efforts to date.

May 5 '06 #6

P: n/a
Mat wrote:
Lyle I dont think that's what I want.

I am asking whether I can use a variable to reference a control on a
subform?

Suppose you have two forms Form1 and Form2 with a control on each Text1
and Text2 and form2 is a subform of form1.

I can refer to the forms and controls in code from the immediate window
by hardcoding either:

forms!form1!form2!Text2

or

forms("form1")("form2")("text2") (this is close
to what I want but would require that I always had only one level of
depth to my subforms to work.)

ideally i want to be able to have a string variable access the control
on any subform.

forms("form1!form2!text2")

or

forms(strVariabletoControlOnAnyFormOrSubForm)

my question is whether this is possible and if so how can i do it?
Perhaps I do not use the forms collection at all?

Thank you for your efforts to date.


You can do this but not in this manner. The key is to determine the name of the *subform
Control* - not the name of the form that is put in that subform control.

The form name of the subform is useless here.

Instead use:

Forms!MainFormNameHere!nameOfSubFormCONTROLhere.Fo rm!nameOfControlOnSubForm

so a main form named "frmMain" with a "sfrmParts" subform contained in a subform control
named sfcParts that has a txtPartNo textbox control might be accessed as so:

Forms!frmMain!sfcParts.Form!txtPartNo.BackColor = vbRed

brokend down you are looking at the Forms collection for "frmMain" and then for a control
on that form named "sfcParts". Since that is a subform control you use the ".Form" to let
you access its form level methods. "txtPartNo" is a control on that subform and you are
setting the BackColor property.

Depending on what you are trying to do there may be more steps involved. A .Requery or
..SetFocus may need a two-step process where you set focus to the sub form control first
and then attempt your method.

Try that....

--
'---------------
'John Mishefske
'---------------
May 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.