How to address a field in a subform ?

  • Thread starter Thread starter Bruno Frisque
  • Start date Start date
B

Bruno Frisque

Hi group,

I want to know the value of a field wich is in a subform on a form.
(OFF XP Dev)

for example what is the syntax for:
Debug.print Forms!Annex1!subform!MyField1

I'v tried many things, but always "Cannot find MyField1"

(The form and his subform are loaded, and MyField1 is there)

Any suggestion ?

Many thanks in advance
 
Bruno said:
Hi group,

I want to know the value of a field wich is in a subform on a form.
(OFF XP Dev)

for example what is the syntax for:
Debug.print Forms!Annex1!subform!MyField1

I'v tried many things, but always "Cannot find MyField1"

(The form and his subform are loaded, and MyField1 is there)

Any suggestion ?

Many thanks in advance

Try:

Debug.print Forms!Annex1!subform.Form!MyField1

Hope this helps,

Peter De Baets
Peter's Software - MS Access Tools for Developers
http://www.peterssoftware.com
 
Hi group,

I want to know the value of a field wich is in a subform on a form.
(OFF XP Dev)

for example what is the syntax for:
Debug.print Forms!Annex1!subform!MyField1

I'v tried many things, but always "Cannot find MyField1"

(The form and his subform are loaded, and MyField1 is there)

Any suggestion ?

Many thanks in advance

The important bit is that the "subform" in the above syntax must be
the name of the Subform Control - the box on the mainform which
contains the subform. The name of the Form within that box is not used
in the expression. For instance, if you have a Form named
"sbfrmMySubform" and the Name property of the Subform control is
"subTheSubform", use

Forms!Annex1!subTheSubform.Form!MyField1

The .Form! *should* be optional but I find it helpful (and less
ambiguous) to routinely include it.

John W. Vinson[MVP]
 
Thanks for your quick replies !
Unfortunately it doesn't work with this code :

Debug.Print "Forms!Annex1!IDCh " & Forms!annex1!frmBRChildrenOnBR.Form!IDCh

Annex1 is the main form and frmBRChildrenOnBR is the subform.

Err msg : cannot find field 'IDCh'

Do I miss something ??
Thanks again
 
Sorry, the debug.print works fine now !!
Debug.Print "Forms!Annex1!IDCh is :" &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
returns 214 wich is perfect !

It is now at the Where code to open a report that I get an err message :
Type Mismatch .

stWhere = "[id]= " & Me.ID And "[IDCh] = " &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
stDocName = "rapMB_29092005_P3_4_Fr"
DoCmd.OpenReport stDocName, acPreview, , stWhere

Thanks again
 
Sorry, the debug.print works fine now !!
Debug.Print "Forms!Annex1!IDCh is :" &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
returns 214 wich is perfect !

It is now at the Where code to open a report that I get an err message :
Type Mismatch .

stWhere = "[id]= " & Me.ID And "[IDCh] = " &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
stDocName = "rapMB_29092005_P3_4_Fr"
DoCmd.OpenReport stDocName, acPreview, , stWhere

Thanks again

You need to move the text "And" inside the quote marks:
stWhere = "[id]= " & Me.ID & " And [IDCh] = " & Forms!annex1!frmBRChildrenOnBR.Form!IDCh
stDocName = "rapMB_29092005_P3_4_Fr"


John W. Vinson[MVP]
 
And it works perfectly !

Many many thanks to you.


John Vinson said:
Sorry, the debug.print works fine now !!
Debug.Print "Forms!Annex1!IDCh is :" &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
returns 214 wich is perfect !

It is now at the Where code to open a report that I get an err message :
Type Mismatch .

stWhere = "[id]= " & Me.ID And "[IDCh] = " &
Forms!annex1!frmBRChildrenOnBR.Form!IDCh
stDocName = "rapMB_29092005_P3_4_Fr"
DoCmd.OpenReport stDocName, acPreview, , stWhere

Thanks again

You need to move the text "And" inside the quote marks:
stWhere = "[id]= " & Me.ID & " And [IDCh] = " & Forms!annex1!frmBRChildrenOnBR.Form!IDCh
stDocName = "rapMB_29092005_P3_4_Fr"


John W. Vinson[MVP]
 
Back
Top