Syntax for accessing subform value

G

Guest

Suppose I have a form called frmMaster with a subform called frmChild, and a
field on the sub form called LastName. How do I get the value of LastName
into a string variable called StrLastName. What is the proper syntax with
exclaimation marks and periods etc.

StrLastName = ????
 
G

Guest

First order of business is what is a subform?
A subform is actually a control object on a form that has a property named
Source Object. The Source Object property identifies the form that will be
presented in the subform control, so make sure you are addressing the name of
the control and not the name of the form presented in the subform control.

The formal syntax would be:
strLastName = Forms!frmMaster!frmChild.Form!LastName
If your code is in frmMaster then
Me.frmChild.Form!LastName

Now, remember if frmChild is the name of the form object, substitute it with
the name of the subform control.
 
G

Guest

Try

StrLastName = Forms![frmMaster]![frmChild].Form![LastName]

Note: The frmChild need to be the name of the Sub form control in the main
form
It might be the same as the sub form name
 
V

Vincent Verheul

Woody said:
Suppose I have a form called frmMaster with a subform called frmChild, and
a
field on the sub form called LastName. How do I get the value of LastName
into a string variable called StrLastName. What is the proper syntax with
exclaimation marks and periods etc.

StrLastName = ????

Try one of these:

StrLastName = frmChild!LastName or
StrLastName = Me.frmChild!LastName or
StrLastName = Me.frmChild!LastName.Value or
StrLastName = Me.frmChild.Form.Controls("LastName") or
StrLastName = Me.frmChild.Form.Controls("LastName").Value
 

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