Setting the background color of a subform

Gkirkup

Registered User.
Local time
Yesterday, 20:09
Joined
Mar 6, 2007
Messages
628
I have a main form which is called in different modes. For each mode I set a background color with Me.detail = a color number.
But on the form are several subforms, and I would like to change the background color of the subforms to match.
This does not work: Me.Mysubform.detail = a color number.
How do I set the color of a subform?

Robert
 
Hi Robert

You could try this:
Me.Mysubform.Form.detail = a color number
 
... or a colour constant, vbRed, vbBlue, vbGreen etc.
 
isn't it this?

mysubform.section("acdetail").backcolor etc


these things are always a matter of just getting the correct syntax. It is all do-able!, and once you have it, you have your own point of reference for future use.

[edit .... and I think my syntax is slightly off ! ]
 
Last edited:
isn't it this?

mysubform.section("acdetail").backcolor etc
Or

mysubform.section(acDetail).backcolor
mysubform.section(0).backcolor
mysubform.section("Section Name").backcolor

All of these are the same as what bob fitz gave.
 
Another way to go about it…

Called from top most Form with:-
SetBackColour Me, vbBlue

Code:
Public Sub SetBackColour(ByRef frmThisForm As Form, _
                         ByVal lngColour As Long)
                         
    Dim Idx As Integer
    Dim Ctl As Control

    [color=green]' Do the Form Sections.[/color]
    If frmThisForm.DefaultView = acDefViewDatasheet Then
        frmThisForm.DatasheetBackColor = lngColour
    Else
        [color=green]' Not all Forms have all Sections.[/color]
        On Error Resume Next
        For Idx = 0 To 4
            frmThisForm.Section(Idx).BackColor = lngColour
        Next Idx
    End If
    
    [color=green]' Do the Form Controls.[/color]
    For Each Ctl In frmThisForm
        If Ctl.ControlType = acSubform Then
            [color=green]' Recursively call the subform.[/color]
            SetBackColour Ctl.Form, lngColour
        End If
    Next Ctl
    
End Sub

Chris.
 
Bob:
That worked, thanks!
Where do I find the color constants? There are so many blues etc, do they all have constants?

Robert
 
The ones I can remember are:

System Colour Constants
Colour Constants
Colour Enumeration

If you type those terms in help it should come up with a short list of colour constants.
 
OK, sounds good. Where do I type those terms? Just in my code?

Robert
 
Hit F1, Help pops-up, type it in the Search box.

OR

Hit F2 and type it in, a list of constants should follow (without descriptions).
 

Users who are viewing this thread

Back
Top Bottom