Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2020
    Posts
    3

    Can't get the BackColor of labels on a subform to reflect the new color— even after I first changed

    I am stumped as to why the BackColor for labels on an MS Access subform will not update visually. I wrote some code to change the BackStyle to "1" first, then changed the color of BackColor. I ran tests and found that the BackStyle and BackColor have actually been updated in the system, but not in the Property Sheet--- which still shows BackStyle as "0" and BackColor as the default color. The color of the label on the subform also retains the default color. I also get no error messages, but that doesn't mean I'm not royally messing something up. I even tried to repaint the form to see if that would do the trick, but to no avail. Here is the simple code below:
    [COLOR=var(--highlight-keyword)]Dim[/COLOR] frm [COLOR=var(--highlight-keyword)]As[/COLOR] Form
    [COLOR=var(--highlight-keyword)]Dim[/COLOR] ctl [COLOR=var(--highlight-keyword)]As[/COLOR] Control


    [COLOR=var(--highlight-keyword)]Set[/COLOR] frm = [COLOR=var(--highlight-keyword)]Me[/COLOR]![subfrm_Review Forecast Totals].Form

    [COLOR=var(--highlight-keyword)]For[/COLOR] [COLOR=var(--highlight-keyword)]Each[/COLOR] ctl [COLOR=var(--highlight-keyword)]In[/COLOR] frm.Controls

    [COLOR=var(--highlight-keyword)]If[/COLOR] ctl.ControlType = acLabel [COLOR=var(--highlight-keyword)]And[/COLOR] ctl.Name = [COLOR=var(--highlight-variable)]"2020-12-25_Label"[/COLOR] [COLOR=var(--highlight-keyword)]Then[/COLOR]

    ctl.BackStyle = [COLOR=var(--highlight-namespace)]1[/COLOR]
    ctl.BackColor = vbGreen



    [COLOR=var(--highlight-keyword)]End[/COLOR] [COLOR=var(--highlight-keyword)]If[/COLOR]

    [COLOR=var(--highlight-keyword)]Next[/COLOR] ctl

    [COLOR=var(--highlight-keyword)]Me[/COLOR].Repaint

    End Sub

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You code isn't readable, but try a form Refresh
    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 ↓↓

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    make sure the label property BACKSTYLE is NOT transparent.
    (normal)

  4. #4
    Join Date
    Dec 2020
    Posts
    3

    Can't get the BackColor of labels on a subform to reflect the new color— even after I first changed

    Quote Originally Posted by ranman256 View Post
    make sure the label property BACKSTYLE is NOT transparent.
    (normal)
    Sorry about the unreadable code earlier. Here is a readable format:

    Dim frm As Form
    Dim ctl As Control


    Set frm = Me![subfrm_Review Forecast Totals].Form

    For Each ctl In frm.Controls

    If[ ctl.ControlType = acLabel And ctl.Name = "2020-12-25_Label" Then

    ctl.BackStyle = 1
    ctl.BackColor = vbGreen

    End If

    Next ctl

    Me.Repaint
    Last edited by VBA_Accountant; 12-18-2020 at 07:46 AM. Reason: Copy and past code did not work.... weird

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    That code looks like CSS?
    Cannot imagine it's possible to use CSS in Access.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    That loop is a bit unnecessary as you are only referring directly to one control?

    Code:
    Dim frm As Form
    Dim ctl As Control
    
    
    Set frm = Me![subfrm_Review Forecast Totals].Form
    
    
    frm.2020-12-25_Label.BackStyle = 1
    frm.2020-12-25_Label.BackColor = vbGreen
    
    frm.repaint
    You have to repaint the subform not the current form, unless you were already on it, which seems unlikely.
    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 ↓↓

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    What kind of Form is your Subform...Single View, Continuous or Datasheet?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    Join Date
    Dec 2020
    Posts
    3
    I'm using a datasheet view/version of the subform via a tab form

  9. #9
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    I am pretty certain you can't change the colour of a Datasheet label.

    Try doing it manually?
    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 ↓↓

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    I think that's correct. Most formatting of Datasheet Forms has to be done using Conditional Formatting off of the Menu/Ribbon....and Labels don't support CF.

    You can do some general formatting of the entire Form, using syntax such as

    Me.DatasheetBackColor = 12713921

    or

    Me.DatasheetBackColor = vbGreen


    to set the BackColor for the entire Form.

    Here's a great site telling you things you can do with Datasheet Forms:

    http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  11. #11
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You can make a continuous form look like a datasheet if that's what it must be. Then you can tweak colours more easily, but there are limits of course.
    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. Replies: 8
    Last Post: 10-14-2019, 02:09 PM
  2. Restore changed data in subform
    By joecamel9166 in forum Forms
    Replies: 2
    Last Post: 07-01-2016, 11:30 AM
  3. Replies: 30
    Last Post: 09-30-2015, 10:58 AM
  4. Replies: 1
    Last Post: 09-10-2014, 11:51 AM
  5. Replies: 0
    Last Post: 10-24-2008, 11:20 AM

Tags for this Thread

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