473,240 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,240 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 2708
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tony Williams | last post by:
I have a form on which there is a tabcontrol and on this onr of the tabpages is a tick box which opens Outlook with data from the main form and prompts the user to amend the message before being...
2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
3
by: shumaker | last post by:
This code from the subform works for getting the value of a field of the main form named "WorkSheet": MsgBox Form_WorkSheet.Recordset.Fields("Clerk").Value Each record in the mainform datasheet...
4
by: mplogue | last post by:
I have a form (frmMain) with a subform (frmSub), each with enumerated fields of the same name (txt1, txt2, etc). I'm trying to make a function that will take the values for each field in frmMain,...
2
by: Axel | last post by:
Hi, a question about something that seems very simple at first glance: is it possible to reference other controls of a subform in a query window without referencing through the parent form? I...
9
by: Alan | last post by:
Hmmm, I'm not too good with the syntax of referencing a subreport. I have frmInvoice which has the invoice details (e.g. ProductCode, ProductCost etc) in the subform frmInvoiceDetails. I'm trying...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
7
by: jundavid | last post by:
have a form and a subform. In the subform, I have a combo box which I would like to only show the records based on the control on the main form. Let say I have a record of employees which I would...
3
by: ManningFan | last post by:
Here's a fun one, mein froinds! I have a form. The form (call it MainForm) has a subform control (call it SubForm). The actual subform that SubForm displays can change based on choices made on...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.