Referencing to a control on a subform

J

Jan T

Hi. I am using Access 2010 and have made a form frmOvertime with a
text box Control named txtEmpID. When I refer to this control I use
the following code:
lngEmpl = [frmOvertime ].Form![txtEmpID]. The code is in a standard
module and this works just fine.

However, when I add frmOvertime to my Navigationform (frmMAIN), as a
SubForm, Access cannot find my control? So I changed my code to
reference to lngEmpl = Forms!frmMAIN!frmOvertime .Form!txtEmpID but I
am stilling getting an error?

Any help to refer to this control, is very much appriciated?

Regards Jan T.
 
B

Bob Quintal

Hi. I am using Access 2010 and have made a form frmOvertime with a
text box Control named txtEmpID. When I refer to this control I use
the following code:
lngEmpl = [frmOvertime ].Form![txtEmpID]. The code is in a standard
module and this works just fine.

However, when I add frmOvertime to my Navigationform (frmMAIN), as a
SubForm, Access cannot find my control? So I changed my code to
reference to lngEmpl = Forms!frmMAIN!frmOvertime .Form!txtEmpID but I
am stilling getting an error?

Any help to refer to this control, is very much appriciated?

Regards Jan T.

When a form is embedded into a subform control, it loses its name.
Access often names the subform control (which is not often the name of
the form it contains) as child1 or somethoing similar.

You can check the .name property of the subform control that contains
your frmOvertime, and refer to that, or you can simply refer to
lngEmpl = me.Parent![txtEmpID].

Hope that helps.
 

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