471,579 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

Referencing a control on a subform

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
6 2621
ray
Forms!MainFormName!subFormControlName.form("YourSt ring")

Ray

May 4 '06 #2
ray
Forms!MainFormName!subFormControlName.form("YourSt ring")

Ray

May 4 '06 #3
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
"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
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
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.

Similar topics

5 posts views Thread by Tony Williams | last post: by
2 posts views Thread by William Wisnieski | last post: by
21 posts views Thread by cmd | last post: by
3 posts views Thread by ManningFan | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.