Results 1 to 5 of 5
  1. #1
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47

    How to reference label in partent subform?

    I have form A which contains subform B which contains subform C. From code in subform C I need to set the caption of a label in subform B.



    Forms![B].[CostumeDescriptionLabel].Caption = rst!Description

    generates the error "3265 Item not found in this collection". What is the right way to reference a component in the parent subform from the child subform? Thanks.

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Forms![A]![B]..... Form B is part of form A, it is not a standalone form.

  3. #3
    Bazsl is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2016
    Posts
    47
    I still get the same error. If I try

    f = Forms![Checkout]![Checkout Event Subform]![CostumeDescriptionLabel]

    I get "Error 438. Object doesn't support this property or method." However, if I shorten the above to

    f = Forms![Checkout]![Checkout Event Subform]

    I do not get an error. There is a Label control on the subform named [CostumeDescriptionLabel].

    My goal is to set the Caption property of the label but I still cannot get the syntax right. Thanks for your help.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In your first post you were giving it a value, in your second that had all changed?

  5. #5
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I've never nested subforms, but try
    Code:
    [Forms]![Main form name]![subformA control name].[Form]![subformB control name].[Form]![Label Name].Caption
    where subform control name is the name of the control that contains the subform - it is not the subform name (although you might have allowed a wizard to have both objects with the same name, which is not a great idea).

    If you're using this in vba, consider creating a control object and setting this syntax to it if you're going to use it more than once. Like
    Dim ctl As Control
    Set ctl = ......
    ctl.Caption = rst!Description
    Last edited by Micron; 02-28-2017 at 09:21 PM. Reason: fixed code tags & additional info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. reference objects on subform
    By gammaman in forum Modules
    Replies: 2
    Last Post: 08-27-2015, 07:31 AM
  2. Replies: 5
    Last Post: 08-09-2012, 12:49 PM
  3. Subform moving line and label
    By hawkins in forum Reports
    Replies: 1
    Last Post: 08-16-2011, 11:15 PM
  4. Creating a reference to the subform.
    By evander in forum Forms
    Replies: 2
    Last Post: 05-26-2010, 09:39 AM
  5. Can't reference control in subform
    By evanscamman in forum Forms
    Replies: 0
    Last Post: 12-25-2007, 06:47 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