unlinked subform

D

Don Barton

I am making a database that acts as a questionnaire that consists of a main
form and 2 subforms. The main form has the person's name, etc. The 1st
subform has the questions. This 1st subform is unlinked. (no child/parent
link). I want the same questions to appear regardless of who is listed in
the main form. The 2nd subform is the answers, which are unique for each
person. The 2nd subform grabs the test taker's name from the main form
(=Forms!frmMainInput!TTName) and the QuestionNumberID from the 1st subform.
I can grab the test taker's name OK, but when I try to grab the questionID
number from the 1st form (=Forms!frmMainInput!frmQuestions!questionID), I get
#Name?. Access doesn't seem to recognize it, even though the 1st subform is
open on the main form, though unlinked. The bottom line is I want the same
set of questions to appear for all person taking the test, and I want to
record the answers for each question by person. I am close, but not quite
there...
 
D

Don Barton

Thanks Tina, that solved the issue. I am just curious though, the rules
governing the syntax for a path to a control on another form don't seem
consistent. Is the rule, "If a subform seeks a value of a control on another
form, the target form must have .Form before the !controlname?" Or is it
only if there is more than one form name in the path? =Forms.frmMain.NameID
worked fine without having to add .Form (=Forms!frmMain.Form!NameID)
--
Don
MS Access DB Developer


tina said:
try

=Forms!frmMainInput!frmQuestions.Form!questionID

in VBA code you usually don't need the ".Form" part of the reference, but in
an expression within a form, you usually do.

btw, you might want to take a look at Duane Hookum's survey database, at
http://www.rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane
to see how his setup works. somebody else's proven design is always a good
learning tool.

hth
 
T

tina

Is the rule, "If a subform seeks a value of a control on another
form, the target form must have .Form before the !controlname?"

no. the issue is not that your expression is on a subform. the issue is that
your expression is looking for a control that's on a subform *that is not
the same form object the expression is in*. in Access (not in VBA), the
syntax is as follows (in all cases, the subform control/subform object have
the same name):

1) FormA, ControlB. expression is on FormA. expression is
= ControlB

2) FormA, SubformB, ControlC on subform. expression is on SubformB.
= ControlC

3) FormA, SubformB, ControlC on subform. but expression is on FormA.
= SubformB.Form!ControlC

4) FormA, SubformB, SubformC, ControlD on FormA, ControlE on SubformB.
expression is on SubformC.
= Forms!FormA!ControlD
= Forms!FormA!SubformB.Form!ControlE

it helps to remember that a subform sits in a subform *control* on its'
parent form. when you refer to the subform in an expression (in Access *and*
in VBA), you're actually referring to the subform control, not the subform
object itself. (a lot of people don't realize this, because when you create
a form/subform with a wizard, it usually gives the subform control the same
name as the subform object. when you begin adding a subform to a form
manually, you don't notice that the control name is usually different than
the subform object name.)

in Access (not in VBA), when you need to refer to a property of the subform
object, you have to specify that the system look at the subform object
contained in the control, rather than looking at the subform control
itself. you do that with the ".Form" reference. the logic is the same with
nested subforms - refer to the name of the subform control, followed by the
".Form" reference.

in VBA, you can usually leave out the .Form reference. i write my code
without the reference, then try adding it if the code returns some kind of
"can't find object" error.

hth


Don Barton said:
Thanks Tina, that solved the issue. I am just curious though, the rules
governing the syntax for a path to a control on another form don't seem
consistent. Is the rule, "If a subform seeks a value of a control on another
form, the target form must have .Form before the !controlname?" Or is it
only if there is more than one form name in the path? =Forms.frmMain.NameID
worked fine without having to add .Form (=Forms!frmMain.Form!NameID)
 

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