Results 1 to 9 of 9
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    Change header Font Colours

    Hi All

    sorry if this has been asked before



    I have this code that runs in a module

    Code:
    Function SelectHeaderColour(frm As Form)
        On Error GoTo SelectHeaderColour_Error
        Dim HeaderColour As String
        HeaderColour = Nz(DLookup("HeaderColour", "tblCompanyDetails"), "Not Setup")
        Select Case HeaderColour
            Case Is = "Light Blue"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(16, 100, 186)
                    frm.Detail.BackColor = RGB(16, 100, 186)
                Else
                    frm.FormHeader.BackColor = RGB(16, 100, 186)
                End If
            Case Is = "Dark Blue"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(16, 50, 139)
                    frm.Detail.BackColor = RGB(16, 50, 139)
                Else
                    frm.FormHeader.BackColor = RGB(16, 50, 139)
                End If
            Case Is = "Black"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(0, 0, 0)
                    frm.Detail.BackColor = RGB(0, 0, 0)
                Else
                    frm.FormHeader.BackColor = RGB(0, 0, 0)
                End If
            Case Is = "Dark Brown"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(138, 51, 36)
                    frm.Detail.BackColor = RGB(138, 51, 36)
                Else
                    frm.FormHeader.BackColor = RGB(138, 51, 36)
                End If
            Case Is = "Crimson"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(220, 20, 60)
                    frm.Detail.BackColor = RGB(220, 20, 60)
                Else
                    frm.FormHeader.BackColor = RGB(220, 20, 60)
                End If
            Case Is = "Not Setup"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(56, 45, 89)
                    frm.Detail.BackColor = RGB(56, 45, 89)
                Else
                    frm.FormHeader.BackColor = RGB(56, 45, 89)
                End If
            Case Is = "Dark Green"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(0, 100, 0)
                    frm.Detail.BackColor = RGB(0, 100, 0)
                Else
                    frm.FormHeader.BackColor = RGB(0, 100, 0)
                End If
            Case Is = "Purple"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(142, 56, 142)
                    frm.Detail.BackColor = RGB(142, 56, 142)
                Else
                    frm.FormHeader.BackColor = RGB(142, 56, 142)
                End If
        End Select
        
        On Error GoTo 0
        Exit Function
    SelectHeaderColour_Error:
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure SelectHeaderColour, line " & Erl & "."
    End Function
    and is called when a form opens by this code

    Code:
    'Get Form Header Colours
        Call SelectHeaderColour(Me) 'Taken From modUtilities
    this works very well and i'm really pleased with it, but i would also like to change the font colour of all controls in the header but I cant get my head around how to do this

    any help would be fantastic

    Steve

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You would have to loop through the controls that you can change the font colour on (Check boxes etc will error) and set the ForeColor property.
    I'm not sure how you would identify that the control was in the Form header though... ?

    Apparently like this
    Code:
    For Each ctl In Me.FormHeader.Controls ...
    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
    sdel_nevo is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Minty

    Many thanks for the help, will look into that

    Steve

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I'm not sure how you would identify that the control was in the Form header though... ?
    Assign a value to the Tag property for only the header controls and loop through the form controls collection, changing the forecolor for only those with the tag value.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    If you don't want to have to touch every control in the header section, another method is to name controls with similar names, like tbx1, tbx2, tbx3, etc. Then looping code can address only those controls:

    For x = 1 to 10
    Me.Controls("tbx" & x).ForeColor = vbRed
    Next

    How many controls are there? If only a few, maybe just addressing each one directly would be just as efficient.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    sdel_nevo is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi June

    what a fantastic idea, will give that a go,

    @micron and Minty many thanks for your help

    Steve

  7. #7
    sdel_nevo is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi

    I thought about this for a while and as I only wanted to change the label and textbox font colours and given that some forms had lots of controls, I tried to filter the controls in the header by type


    using this code

    Code:
    Function SelectHeaderColour(frm As Form)
       
        Dim HeaderColour As String
        Dim ctl As Control
        
        HeaderColour = Nz(DLookup("HeaderColour", "tblCompanyDetails"), "Not Setup")
        Select Case HeaderColour
            Case Is = "Light Blue"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(16, 100, 186)
                    frm.Detail.BackColor = RGB(16, 100, 186)
                Else
                    frm.FormHeader.BackColor = RGB(16, 100, 186)
                End If
            Case Is = "Dark Blue"
            
                For Each ctl In frm.FormHeader.Controls
                    With ctl
                        Select Case .ControlType
                            Case acLabel
                                .ForeColor = vbRed
                            Case acTextBox
                                .ForeColor = vbRed
                        End Select
                    End With
                Next ctl
                                  
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(16, 50, 139)
                    frm.Detail.BackColor = RGB(16, 50, 139)
                    
                Else
                    frm.FormHeader.BackColor = RGB(16, 50, 139)
                End If
            Case Is = "Black"
            
                For Each ctl In frm.FormHeader.Controls
                    With ctl
                        Select Case .ControlType
                            Case acLabel
                                .ForeColor = RGB(255, 255, 255)
                            Case acTextBox
                                .ForeColor = RGB(255, 255, 255)
                        End Select
                    End With
                Next ctl
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(0, 0, 0)
                    frm.Detail.BackColor = RGB(0, 0, 0)
                Else
                    frm.FormHeader.BackColor = RGB(0, 0, 0)
                End If
            Case Is = "Dark Brown"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(138, 51, 36)
                    frm.Detail.BackColor = RGB(138, 51, 36)
                Else
                    frm.FormHeader.BackColor = RGB(138, 51, 36)
                End If
            Case Is = "Red"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(220, 20, 60)
                    frm.Detail.BackColor = RGB(220, 20, 60)
                Else
                    frm.FormHeader.BackColor = RGB(220, 20, 60)
                End If
            Case Is = "Not Setup"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(56, 45, 89)
                    frm.Detail.BackColor = RGB(56, 45, 89)
                Else
                    frm.FormHeader.BackColor = RGB(56, 45, 89)
                End If
            Case Is = "Dark Green"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(0, 100, 0)
                    frm.Detail.BackColor = RGB(0, 100, 0)
                Else
                    frm.FormHeader.BackColor = RGB(0, 100, 0)
                End If
            Case Is = "Purple"
                If frm.Name = "frmDashboard" Then
                    frm.FormHeader.BackColor = RGB(142, 56, 142)
                    frm.Detail.BackColor = RGB(142, 56, 142)
                Else
                    frm.FormHeader.BackColor = RGB(142, 56, 142)
                End If
        End Select
    I managed to do what I wanted , I don't have to rename any controls or add tags, i'm not sure its the most graceful way of doing things but it works really well


    Steve

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    That is probably as elegant as it could be, and has the added bonus that if you add another control to that section or rename it it will still work on those new / updated controls, as it's not hard coded.
    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 ↓↓

  9. #9
    sdel_nevo is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Minty

    yes I have just added some to a form to test it, works really well, im really happy with it

    its my first attempt at righting a function after one hell of a learning curve, getting there slowly now

    steve

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

Similar Threads

  1. VBA to change font color
    By data808 in forum Access
    Replies: 5
    Last Post: 10-23-2014, 11:10 AM
  2. Replies: 4
    Last Post: 08-03-2014, 10:10 PM
  3. How to change font color in a form?
    By Jamesiv1 in forum Access
    Replies: 6
    Last Post: 05-16-2014, 03:24 PM
  4. Changing Font in Access Report Header
    By ZLHysong in forum Access
    Replies: 1
    Last Post: 02-01-2013, 03:17 PM
  5. Change font color in subform
    By rtrinidad in forum Forms
    Replies: 1
    Last Post: 11-04-2012, 01:42 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