Results 1 to 14 of 14
  1. #1
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296

    Subform not found when trying to change detail backcolor?

    I am trying to change the detail backcolor for a subform but I cannot figure out the syntax to reference the detail.
    I have tried a few different ways and get different errors.



    This is the code I am currently trying and it says form cannot be found
    Code:
    Forms!SFrm_Main.Detail.BackColor
    Would someone please help me write this correctly?

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Maybe try Forms!SFrm_Main.Form.Detail.BackColor
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Gicu View Post
    Maybe try Forms!SFrm_Main.Form.Detail.BackColor
    It says it can't find the referenced form 'SFrm_Main'
    Click image for larger version. 

Name:	Capture.PNG 
Views:	16 
Size:	2.3 KB 
ID:	49965

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    this syntax usually works to get to the subform. Add a control or property reference after that. Make sure that subform control name is the name of the control that contains the subform.
    [Forms]![Main form name]![subform control name].[Form]

    [Forms]![Main form name]![subform control name].[Form].Detail.Backcolor = vbred
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    I always rename my subform controls to contMySubformName - which in my world mean the subform container, which by osmosis helps me remember the subform name.
    It avoids any confusion where the control and the subform in holds are called the same thing.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  6. #6
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Micron View Post
    this syntax usually works to get to the subform. Add a control or property reference after that. Make sure that subform control name is the name of the control that contains the subform.
    [Forms]![Main form name]![subform control name].[Form]

    [Forms]![Main form name]![subform control name].[Form].Detail.Backcolor = vbred
    I took Minty's advice about naming the container with Cont.
    Ways I tried:
    Forms!Main!ContSFrm_Main.SFrm_Main.Detail.BackColo r (Object does not support property)
    Forms!Main!SFrm_Main.ContSFrm_Main.Detail.BackColo r (Cannot find the field 'SFrm_Main'(As expected cause its now named with Cont))
    Forms!Main!ContSFrm_Main.ContSFrm_Main.Detail.Back Color (Object does not support property
    Forms!Main!ContSFrm_Main.Detail.BackColor (Object does not support property)

    Just to confirm I have a container named "ContSFrm_Main" and the source object is "SFrm_Main".
    SFrm_Main is also unbound with no table but I don't think that affects it.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    None of those use Form. after the subform control name. Form. isn't a reference - it's a requirement.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Micron View Post
    None of those use Form. after the subform control name. Form. isn't a reference - it's a requirement.
    Ahhhh! I misunderstood because it was in brackets like the other references. My bad!
    Fixing this worked!
    Code:
    Forms!Main!ContSFrm_Main.Form.Detail.BackColor
    This is the code that worked for anyone in the future.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Brackets are required if names contain spaces or Heaven forbid, start with a number, so that's what they're meant to signify. Putting them in causes no harm but in retrospect, I probably should remove them from Forms! . Not sure if that would have helped though. I guess I will remove from both though going forward. That was a clip from a text file that I have.

    Maybe review a couple of naming conventions
    https://www.devhut.net/naming-conventions/
    http://theaccessweb.com/general/gen0012.htm
    https://www.access-programmers.co.uk.../#post-1152269
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Perhaps learn the structure of how to refer to controls from elsewhere than the form itself?

    http://access.mvps.org/access/forms/frm0031.htm
    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

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Quote Originally Posted by Minty View Post
    I always rename my subform controls to contMySubformName - which in my world mean the subform container, which by osmosis helps me remember the subform name.
    It avoids any confusion where the control and the subform in holds are called the same thing.
    I used to do the same by prefixing with ctl.
    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

  12. #12
    Vita's Avatar
    Vita is offline Competent Performer
    Windows 10 Access 2002
    Join Date
    May 2022
    Location
    Massachusetts, USA
    Posts
    296
    Quote Originally Posted by Micron View Post
    Brackets are required if names contain spaces or Heaven forbid, start with a number, so that's what they're meant to signify. Putting them in causes no harm but in retrospect, I probably should remove them from Forms! . Not sure if that would have helped though. I guess I will remove from both though going forward. That was a clip from a text file that I have.

    Maybe review a couple of naming conventions
    https://www.devhut.net/naming-conventions/
    http://theaccessweb.com/general/gen0012.htm
    https://www.access-programmers.co.uk.../#post-1152269
    I will give these a read. I like to think I have been doing a fairly good job.
    Textboxes end with Txt
    Labels end with Lbl
    the main form is called "Main" and subform is "Sfrm_Main"
    Buttons have a "Bttn" Suffix. (side note: Kind of upset you can't change button colors in earlier versions of access)
    There are 1 or 2 exceptions to these rules otherwise. I will def read though!
    I also only put brackets if the name has spaces (or starts with numbers which has never been something I've done). I could read it either way.


    Quote Originally Posted by Welshgasman View Post
    Perhaps learn the structure of how to refer to controls from elsewhere than the form itself?

    http://access.mvps.org/access/forms/frm0031.htm
    This also seems like valuable reading! I was struggling with this a bit.

    Thank you both!

  13. #13
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    I prefixed my controls with values like those, rather than suffixed. Easier to see at at glance, was my thoughts?
    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

  14. #14
    Edgar is offline Competent Performer
    Windows 8 Access 2016
    Join Date
    Dec 2022
    Posts
    271
    It's good that OP found a solution, but you guys are making this look like it's a guessing game and it's NOT. Everything is in the form variable. The link you've been using for consultation and referencing forms is archaic and needlessly complex.
    Last edited by Edgar; 03-23-2023 at 12:46 PM. Reason: less dramatic

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

Similar Threads

  1. Replies: 10
    Last Post: 12-18-2020, 11:37 AM
  2. Replies: 3
    Last Post: 12-15-2016, 04:02 PM
  3. Replies: 7
    Last Post: 08-23-2014, 05:52 AM
  4. If/Else If help to Change BackColor
    By SpdRacerX in forum Access
    Replies: 2
    Last Post: 03-20-2012, 10:09 AM
  5. Replies: 1
    Last Post: 10-22-2009, 03:32 AM

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