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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting BackColor on Textbox controls with vba. 1

Status
Not open for further replies.

yonate

Programmer
Mar 18, 2010
2
US

I am trying to learn about how to set background colors of controls in a report in Access 2003. I can not make a programmatic setting of the BackColor property to work for anything except whole sections (last line when uncommented). I'm a newbie to access and vba so I'm sure I'm just missing something fundamental. Following is code in the reports Detail_Format event handler that I'm puzzled over. The Messages confirm that the property is being set on the controls but the background color is not changing.

(BTW, don't try the following code on a report with a lot of details or the message will go off for each detail :)
Thanks for any help.


Dim cCont As Control
Dim sM As String
Dim headingBGColor As Long
headingBGColor = 8404992
For Each cCont In Me.Section(acDetail).Controls
sM = sM & " " & TypeName(cCont)
If TypeName(cCont) = "Textbox" Then
cCont.BackColor = headingBGColor
sM = sM & "(" & CStr(cCont.Name) & ": " & CStr(cCont.BackColor) & ")"
End If
Next cCont
MsgBox (sM)
' Try a few direct property sets and they dont work either
Me.tbTBD.BackColor = headingBGColor
Me.Low.BackColor = headingBGColor
Me.Label29.BackColor = headingBGColor
'Me.Section(acDetail).BackColor = headingBGColor
 
I did this with a simple report and hard coded values and it worked. Maybe the issue is how your variables are being defined.

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me.txtEndTerm = 2009 Then
    Me.txtEndTerm.BackColor = vbRed
End If
End Sub
 
Thanks dhookom.

I changed the background style of the controls to Normal (was transparent) and that fixed it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top