Background, foreground

S

SHIPP

I have written the following code in Access 2003 to change the background and
foreground colors of the fields. Sunday works just fine. After that if it
executes the else command both the foreground and background are shifted to
white (You can't see anything on the report). Any ideas?

' Firm Orders
If Me.FirmSun = 0 Then
Me.txtSunOrd.FontBold = False
Me.txtSunOrd.BackColor = vbWhite
Me.txtSunOrd.ForeColor = vbBlack
Else
Me.txtSunOrd.FontBold = True
Me.txtSunOrd.BackColor = vbBlue
Me.txtSunOrd.ForeColor = vbWhite
End If
If Me.FirmMon = 0 Then
Me.txtMonOrd.FontBold = False
Me.txtMonOrd.BackColor = vbWhite
Me.txtMonOrd.ForeColor = vbBlack
Else
' This code shifts the foreground and background to white. Consequently you
can't see anything on the report.
Me.txtMonOrd.FontBold = True
Me.txtMonOrd.BackColor = vbBlue
Me.txtMonOrd.ForeColor = vbWhite
End If
If Me.FirmTue = 0 Then
Me.txtTueOrd.FontBold = False
Me.txtTueOrd.BackColor = vbWhite
Me.txtTueOrd.ForeColor = vbBlack
Else
Me.txtTueOrd.FontBold = True
Me.txtTueOrd.BackColor = vbBlue
Me.txtTueOrd.ForeColor = vbWhite
End If
If Me.FirmWed = 0 Then
Me.txtWedOrd.FontBold = False
Me.txtWedOrd.BackColor = vbWhite
Me.txtWedOrd.ForeColor = vbBlack
Else
Me.txtWedOrd.FontBold = True
Me.txtWedOrd.BackColor = vbBlue
Me.txtWedOrd.ForeColor = vbWhite
End If
If Me.FirmThu = 0 Then
Me.txtThuOrd.FontBold = False
Me.txtThuOrd.BackColor = vbWhite
Me.txtThuOrd.ForeColor = vbBlack
Else
Me.txtThuOrd.FontBold = True
Me.txtThuOrd.BackColor = vbBlue
Me.txtThuOrd.ForeColor = vbWhite
End If
If Me.FirmFri = 0 Then
Me.txtFriOrd.FontBold = False
Me.txtFriOrd.BackColor = vbWhite
Me.txtFriOrd.ForeColor = vbBlack
Else
Me.txtFriOrd.FontBold = True
Me.txtFriOrd.BackColor = vbBlue
Me.txtFriOrd.ForeColor = vbWhite
End If
If Me.FirmSat = 0 Then
Me.txtSatOrd.FontBold = False
Me.txtSatOrd.BackColor = vbWhite
Me.txtSatOrd.ForeColor = vbBlack
Else
Me.txtSatOrd.FontBold = True
Me.txtSatOrd.BackColor = vbBlue
Me.txtSatOrd.ForeColor = vbWhite
End If
 
S

SHIPP

More information.

It is the background statement that isn't working. The foreground statement
does in fact change the type to white. However the background statement does
not change the background color. It leaves it as blue. I also tried the
following statement to no avail. It also left the background white.

Me.txtTueOrd.BackColor = QBColor(0)
 
G

George Nicholson

Just a guess:
Make sure BackStyle is Normal (not Transparent). When setting Backcolor to
White, that setting might not matter (on a White report page), but it does
when setting it to anything else. Sometimes Access changes this to Normal
for you Automatically when you manually change a color, but I have no idea
if it will do that while running code.

I've taken the liberty of revising your code so that you Loop though the
exact same set of instructions for each control.
If you still have a problem, at least you'll only have one place to
implement a fix.

In any case, if Sunday is fine but the rest are not, then look for
differences in the property settings of the controls since the code is
identical.

Dim vList as Variant
Dim i as Integer
Dim ctl as Control

vList = Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat")

For i = LBound(vList) to Ubound(vList)
Set ctl = Me.Controls("txt"& vList(i) & "Ord")
If Me.Controls("Firm"& vList(i) = 0 Then
ctl.FontBold = False
ctl.BackColor = vbWhite
ctl.ForeColor = vbBlack
Else
ctl.FontBold = True
ctl.Backstyle = 1 'Normal
ctl.BackColor = vbBlue
ctl.ForeColor = vbWhite
End If
Next i
Set ctl = Nothing

....and Yes, I know the above could be "improved" in this particular case by
replacing vList with Format(i,"ddd"), but I deliberately chose the Array
route because not every set of controls happen to have such convenient names
:)
 
S

SHIPP

Very tight code. Thank you so much.
--
M. Shipp


George Nicholson said:
Just a guess:
Make sure BackStyle is Normal (not Transparent). When setting Backcolor to
White, that setting might not matter (on a White report page), but it does
when setting it to anything else. Sometimes Access changes this to Normal
for you Automatically when you manually change a color, but I have no idea
if it will do that while running code.

I've taken the liberty of revising your code so that you Loop though the
exact same set of instructions for each control.
If you still have a problem, at least you'll only have one place to
implement a fix.

In any case, if Sunday is fine but the rest are not, then look for
differences in the property settings of the controls since the code is
identical.

Dim vList as Variant
Dim i as Integer
Dim ctl as Control

vList = Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat")

For i = LBound(vList) to Ubound(vList)
Set ctl = Me.Controls("txt"& vList(i) & "Ord")
If Me.Controls("Firm"& vList(i) = 0 Then
ctl.FontBold = False
ctl.BackColor = vbWhite
ctl.ForeColor = vbBlack
Else
ctl.FontBold = True
ctl.Backstyle = 1 'Normal
ctl.BackColor = vbBlue
ctl.ForeColor = vbWhite
End If
Next i
Set ctl = Nothing

....and Yes, I know the above could be "improved" in this particular case by
replacing vList with Format(i,"ddd"), but I deliberately chose the Array
route because not every set of controls happen to have such convenient names
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top