Change form colour on load (1 Viewer)

tacieslik

Registered User.
Local time
Today, 07:44
Joined
May 2, 2001
Messages
244
I want to get the following code to change the forms back ground colour on load. Can anyone help?

Private Sub Form_Load()

Forms!frmTEST!txtColour.BackColor = 13408767

End Sub

I tried:

Private Sub Form_Load()

Forms!frmTEST.BackColor = 13408767

End Sub

But had no luck!
TIA
 

Mile-O

Back once again...
Local time
Today, 07:44
Joined
Dec 10, 2002
Messages
11,316
Have you looked at a form's properties properly?

Forms don't have a BackColor property - or any colour property for that matter.

You use the Detail object to change the background colour.

Code:
Me.Detail.BackColor = 13408767
 

tacieslik

Registered User.
Local time
Today, 07:44
Joined
May 2, 2001
Messages
244
Thanks Mile-O-Phile, No I had not. But I can see what I was doing wrong now!

Many Thanks
 
Last edited:

tacieslik

Registered User.
Local time
Today, 07:44
Joined
May 2, 2001
Messages
244
Hello Mile,

I want to use this code in all forms on load:

Code:
Private Sub Form_Load()
    
    Me.Detail.BackColor = Forms!frmAdminControl!cmbFormBackColour
    Me!lblColour.ForeColor = Forms!frmAdminControl!cmbFormForeColour
    Me!btnTextColour.ForeColor = Forms!frmAdminControl!cmbButtonForeColour
    
End Sub


However, to enter all the different text labels and buttons would take some time. Is it possible to modify this code so that:
All labels are made the colour chosen in the relevant combo
All Button fore colours are made the colour chosen in the relevant combo
I will also have to add to the code to allow for text boxes and their labels.

TIA
 

Mile-O

Back once again...
Local time
Today, 07:44
Joined
Dec 10, 2002
Messages
11,316
Code:
Private Sub Form_Load()
    
    ' create a control variable
    Dim ctl As Control
    ' use constant
    Const strForm = "frmAdminControl"

    ' change colour of form
    Me.Detail.BackColor = Forms(strForm).cmbFormBackColour

    ' loop through form's controls (i.e. the form's controls collection)
    For Each ctl In Me
        ' examine the control type
        Select Case ctl.ControlType
            ' if control is a command buttons
            Case Is = acCommandButton
                ' change button forecolour to that on referenced form
                ctl.ForeColor = Forms(strForm).cmbButtonForeColour
            Case Is = acLabel
                ' change button forecolour to that on referenced form
                ctl.ForeColor = Forms(strForm).cmbFormForeColour
        End Select
    Next ' move to next control in collection

   Set ctl = Nothing ' empty the control variable
    
End Sub

And just add a different case for each control...
 
Last edited:

tacieslik

Registered User.
Local time
Today, 07:44
Joined
May 2, 2001
Messages
244
Thanks Mile,

I think I understand it, so I'll give it a whirl.
Cheers.
 

tacieslik

Registered User.
Local time
Today, 07:44
Joined
May 2, 2001
Messages
244
Thanks Mile, Yes I do understand now. It's a bit of a loop thing.

Many Thanks,
TAC
 

Users who are viewing this thread

Top Bottom