Results 1 to 10 of 10
  1. #1
    Ant_Snell is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    UK
    Posts
    118

    Referring to a field in an open form (sub form in a sub form)

    In a query I want to refer to a field in an open sub form. I have done this many times using [Forms]![MAIN FORM NAME]![SUB FORM NAME].[Form]![FIELD NAME] however this time I want to drill down to a sub form within a sub form. If I use the Expression Builder, it does not show the 2nd sub form. I have tried typing:
    Forms![frm_Index_MyDetails]![frm_Emp_MyDetails]![frm_Emp_MyAbsence].[Form]![Emp_Absence_ID]
    With the error message. The expression you entered has invalid .(dot) or ! operator or invalid parentheses.
    Therefore my question is how do I refer to a field in a sub form within another sub form? Thanks

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi Ant

    You can use this:-

    [Forms]![MAIN FORM NAME]![SUB FORM1 NAME]![SUB FORM2 NAME].[Form]![FIELD NAME]
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Quote Originally Posted by Ant_Snell View Post
    In a query I want to refer to a field in an open sub form. I have done this many times using [Forms]![MAIN FORM NAME]![SUB FORM NAME].[Form]![FIELD NAME] however this time I want to drill down to a sub form within a sub form. If I use the Expression Builder, it does not show the 2nd sub form. I have tried typing:
    Forms![frm_Index_MyDetails]![frm_Emp_MyDetails]![frm_Emp_MyAbsence].[Form]![Emp_Absence_ID]
    With the error message. The expression you entered has invalid .(dot) or ! operator or invalid parentheses.
    Therefore my question is how do I refer to a field in a sub form within another sub form? Thanks
    The following site may be of interest: http://access.mvps.org/access/forms/frm0031.htm
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Ant_Snell is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jul 2021
    Location
    UK
    Posts
    118
    Thanks Bob a few things there to try

  5. #5
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,540
    Quote Originally Posted by Ant_Snell View Post
    Thanks Bob a few things there to try
    Post a copy of the db if you still can't get it working.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by mike60smart View Post
    Hi Ant

    You can use this:-

    [Forms]![MAIN FORM NAME]![SUB FORM1 NAME]![SUB FORM2 NAME].[Form]![FIELD NAME]
    Actually NOT the subform name, but the subform CONTROL name. Not even sure that above is correct?, I would have thought the .Form element would be in there somewhere?
    Cannot test as on phone. Bob's link should set you right anyway.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Sorry my mistake

    [Forms]![MAIN FORM NAME]![SUB FORM1]![SUB FORM2].[Form]![ControlNAME]
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by mike60smart View Post
    Sorry my mistake

    [Forms]![MAIN FORM NAME]![SUB FORM1]![SUB FORM2].[Form]![ControlNAME]
    Still got it wrong Mike?

    Me!Subform1.Form!Subform2.Form!ControlName

    For these examples:
    Mainform is the name of the top level form
    Subform1 is the name of the subform CONTROL on mainform
    Subform2 is the name of the subform CONTROL on the 1st subform.


    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,563
    Hi WGM

    You are correct going by the Forms Reference link.

    Me!Subform1.Form!Subform2.Form!ControlName
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,914
    Quote Originally Posted by mike60smart View Post
    Hi WGM

    You are correct going by the Forms Reference link.

    Me!Subform1.Form!Subform2.Form!ControlName
    That is where I copied that text from?
    Think about it, for one subform control you have to use subformcontrol!Form!Controlname, so you are just doubling up.
    The second subformcontrol is still just a control, then you need it's Form, and then the controlname on that subform.

    All about hierarchy.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-11-2020, 07:14 AM
  2. Replies: 3
    Last Post: 10-02-2019, 01:46 PM
  3. Replies: 16
    Last Post: 06-21-2017, 08:44 PM
  4. Replies: 5
    Last Post: 10-18-2016, 06:00 AM
  5. Replies: 1
    Last Post: 12-04-2011, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums