Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting backcolor of subform in VBA

Status
Not open for further replies.

bez999

Programmer
Oct 3, 2003
99
0
0
GB
Hi Guys
I have a form with a subform and I want to change the background colour of the subform to indicate various statuses during a process. I thought I could just say:
Me.SubFormName.Backcolor = SomeColour
but it doesn't work.
I'm using Access 2003.
Any ideas, please?

Regards
Chris Bezant
 
Try following if the event is on sub form

Me.Detail.BackColor = 13882281
Me.FormFooter.BackColor = 13882281
Me.FormHeader.BackColor = 13882281

Hope this helps

Jimmy

 
Thanks for responding, Jimmy.
The event is on the main form but you have given me an idea. If I create a public sub in the subform that resets the colour I could call it from the main form.

Regards
Chris Bezant
 
Froms do not have backcolor. Only sections of forms.

Me.subFrmControlName.Form.Section(acDetail).BackColor = someColor

sections are:
0 acDetail Form detail section
1 acHeader Form header section
2 acFooter Form footer section
3 acPageHeader Form page header section
4 acPageFooter Form page footer section

 
If not clear. The above code is how you call it from the main form.
 
Thanks MajP I will give that a try.
In the meantime I came up with this solution:
In the subform I created the following code:

' This is called from the main screen to reflect the status of each race
Public Sub ChangeBackgroundColour(Colour As Long)
Me.FormHeader.BackColor = Colour
Me.Detail.BackColor = Colour
Me.FormFooter.BackColor = Colour
End Sub

Private Sub Form_Load()
ChangeBackgroundColour NeutralColour
End Sub

Public Function GetBackgroundColour() As Long
GetBackgroundColour = Me.Detail.BackColor
End Function

The background colour of the subform is then set in the main form code using:
Forms!MainFormF.Runner1SubF.Form.ChangeBackgroundColour NeutralColour


Regards
Chris Bezant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top