Child Reference Syntax?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form that opens another form. The second form has a subform within
it, and I'd like to run a test before the form is displayed, whether or not a
field within the subform has a null value. My problem lies in the syntax,
I've searched the forums to find this syntax:

Me!subformcontrol.form.testedfield

where subformcontrol is the name of the subform control in the Parent form
and testedfield is the field within the subform that I would like to test.

I get an error stating that the "subformcontrol" field cannot be found. Is
this syntax correct? I appreciate any advice/suggestions. Thanks in advance
 
Neil Cash said:
I have a form that opens another form. The second form has a subform
within it, and I'd like to run a test before the form is displayed,
whether or not a field within the subform has a null value. My
problem lies in the syntax, I've searched the forums to find this
syntax:

Me!subformcontrol.form.testedfield

where subformcontrol is the name of the subform control in the Parent
form and testedfield is the field within the subform that I would
like to test.

I get an error stating that the "subformcontrol" field cannot be
found. Is this syntax correct? I appreciate any advice/suggestions.
Thanks in advance

The syntax would be correct if the subform were on the same form where
the code is running, but you say it's on a second form. So at the very
least you need to replace the "Me" keyword with a reference to that
form. If the other form were named "SecondForm", you'd use this:

Forms!SecondForm!subformcontrol.Form.testedfield

HOWEVER, it sounds from your description as if you want to check this
value before you actually open the form. The above reference to
SecondForm won't be valid unless SecondForm is open. Instead, you might
use a DLookup function expression to examine the value you're curious
about, directly in the table where it is stored. You'd need to figure
out what criteria to apply in the call to DLookup, so as to get just the
specific record you want. Your code might look vaguely like

If IsNull(DLookup("testedfield", "SomeTable", _
"SomeField=" & Me.SomeField & _
"AND OtherField=" & Me.OtherField)) _
Then
' do something
Else
' do something else
End If
 
You were right, the Dlookup function was the way to go, and it works
wonderfully. Thank you so much.
 
Back
Top