Referring to Field Values in a Sub Form

D

David Altemir

Hello ...

I've got the following code under a button in an Access 2000 main form
called "CAList":

stDocName = "CAEditor"
stLinkCriteria = "CAID = " & Me.CAListSubForm![CAID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

I get a "Access can't find the field 'CAListSubForm' referred to in
your expression" error. But the same coding approach works without
error in an analogous case that I have defined in another main form,
"NCRList":

stDocName = "NCREditor"
stLinkCriteria = "NCRID = " & Me.NCRListSubForm![NCRID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Therefore, the same kind of statement works for "CAList" but not
"NCRList"!!! "CAList" and "NCRList" are main forms that are open when
each of these code bits are executed, respectively.

Can anyone tell me what fundamental problem am I having when referring
to field values in a subform? My inclination would have been to use
exclamation marks in the field path names (i.e.,
Me!NCRListSubForm![NCRID]) instead of a period, but like I say, the
period worked for me in "NCRList".
-- David
 
A

Allen Browne

Open the form in design view.
Right-click the edge of the subform control, and choose Properties.
What is the Name of the subform control ("Other" tab)?

The Name of the control can be different from its SourceObject (i.e. the
name of the form that is loaded into the subform control).

If "CAID" is a field in the subform, strictly you should also include the
".Form" bit to refer to the form in the subform control. Although Access
often lets you get away without doing this, there are contexts where this
will get you out of trouble. More info:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html
 
D

David Altemir

That did the trick!! Thank you very much!

Allen Browne said:
Open the form in design view.
Right-click the edge of the subform control, and choose Properties.
What is the Name of the subform control ("Other" tab)?

The Name of the control can be different from its SourceObject (i.e. the
name of the form that is loaded into the subform control).

If "CAID" is a field in the subform, strictly you should also include the
".Form" bit to refer to the form in the subform control. Although Access
often lets you get away without doing this, there are contexts where this
will get you out of trouble. More info:
Referring to Controls on a Subform
at:
http://allenbrowne.com/casu-04.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.


David Altemir said:
Hello ...

I've got the following code under a button in an Access 2000 main form
called "CAList":

stDocName = "CAEditor"
stLinkCriteria = "CAID = " & Me.CAListSubForm![CAID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

I get a "Access can't find the field 'CAListSubForm' referred to in
your expression" error. But the same coding approach works without
error in an analogous case that I have defined in another main form,
"NCRList":

stDocName = "NCREditor"
stLinkCriteria = "NCRID = " & Me.NCRListSubForm![NCRID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Therefore, the same kind of statement works for "CAList" but not
"NCRList"!!! "CAList" and "NCRList" are main forms that are open when
each of these code bits are executed, respectively.

Can anyone tell me what fundamental problem am I having when referring
to field values in a subform? My inclination would have been to use
exclamation marks in the field path names (i.e.,
Me!NCRListSubForm![NCRID]) instead of a period, but like I say, the
period worked for me in "NCRList".
-- David
 

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