Set Form ForeColor OnLoad (1 Viewer)

AJR

Registered User.
Local time
Today, 23:37
Joined
Dec 22, 2012
Messages
59
Hi and thanks for taking the time

I am writing a new database and am setting up some templates. In order to make changing the color of elements in forms and reports easy I would like to define them when the form loads.

I have created a module to define the colors by using public variables. e.g.,

Code:
Public longForeColor as Long

longForeColor = RGB(###,###,###)
Hi

Now, in the OnLoad event of my form template I would like to set the ForeColor for all controls. My problem is that I can't figure out how to reference this. It would seem to me that I should be able to do something like this.

Code:
Private Sub Form_Load()

    Me.ForeColor=longForeColor

End Sub
Hi

That way I could change the ForeColor in all my forms simply by changing the value of longForeColor.

Using Me.ForeColor doesn't work and I'm wondering how (or if) one can set the ForeColor for all controls that will be created using this template.

I have found lots of information on doing this to individual controls but not to an entire form.

Thanks
AR
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:37
Joined
May 7, 2009
Messages
19,248
call this sub on the form's Open event:

Private Sub Form_Open(Cancel As Integer)
RecolorForm Me, r, g, b
End Sub

substitute your rgb color for the blue-colored one.
Code:
Public Sub RecolorForm(ByRef frm As Access.Form)

    Dim ctrl As Access.Control
    
    For Each ctrl In frm.Controls
    
        'If TypeOf ctrl Is Access.TextBox Or _
        '        TypeOf ctrl Is Access.ComboBox Or _
        '        TypeOf ctrl Is Access.ListBox Then
        'End If
        If TypeOf ctrl Is Access.SubForm Then
            RecolorForm ctrl.Form
        Else
            ctrl.ForeColor = fnForeColor
        End If
        
    Next
                
End Sub

Public Function fnForeColor(Optional r As Variant, Optional g As Variant, Optional b As Variant)
    If IsMissing(r) And IsMissing(g) And IsMissing(b) Then
        fnForeColor = 0
    Else
        fnForeColor = RGB(CLng(r), CLng(g), CLng(b))
    End If
End Function
 

sneuberg

AWF VIP
Local time
Today, 08:37
Joined
Oct 17, 2014
Messages
3,506
call this sub on the form's Open event:

Private Sub Form_Open(Cancel As Integer)
RecolorForm Me, r, g, b
End Sub

substitute your rgb color for the blue-colored one.

I think you forgot to include the color parameters in the RecolorForm subroutine.
 

AJR

Registered User.
Local time
Today, 23:37
Joined
Dec 22, 2012
Messages
59
call this sub on the form's Open event:

Private Sub Form_Open(Cancel As Integer)
RecolorForm Me, r, g, b
End Sub

substitute your rgb color for the blue-colored one.
Code:
Public Sub RecolorForm(ByRef frm As Access.Form)

    Dim ctrl As Access.Control
    
    For Each ctrl In frm.Controls
    
        'If TypeOf ctrl Is Access.TextBox Or _
        '        TypeOf ctrl Is Access.ComboBox Or _
        '        TypeOf ctrl Is Access.ListBox Then
        'End If
        If TypeOf ctrl Is Access.SubForm Then
            RecolorForm ctrl.Form
        Else
            ctrl.ForeColor = fnForeColor
        End If
        
    Next
                
End Sub

Public Function fnForeColor(Optional r As Variant, Optional g As Variant, Optional b As Variant)
    If IsMissing(r) And IsMissing(g) And IsMissing(b) Then
        fnForeColor = 0
    Else
        fnForeColor = RGB(CLng(r), CLng(g), CLng(b))
    End If
End Function

Arnelgp

Thanks for that. It's a little complicated for me but I am wading through it.

So I am assuming that there is no universal way to define the forecolor in a form the same way as one can with a control?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:37
Joined
May 7, 2009
Messages
19,248
u need universal color, have you tried the Themes on the ribbon on while on form design view.
 

Users who are viewing this thread

Top Bottom