Conditional format

H

Hanksor

I have a report that has a textbox named "Total2004" with a data source of
Total04. I would like to have the background color change if the value of
Total2004 is 0. Below is the code I have at this point, but all backgrounds
of total2004 change instead of just the ones with a value of 0.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Total2004].Value = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
End If
End Sub

Where am I going wrong? I'm using 97 so I don't have the use of conditional
formating.... Any help will be appreciated.

Thanx,
 
R

Rick B

Why are you using code? Use the built-in conditional formatting feature
that is in the FORMAT menu.
 
H

Hanksor

Because, as I stated in my post, We only have 97 here and I don't have the
built-in conditional formatting feature.
Rick B said:
Why are you using code? Use the built-in conditional formatting feature
that is in the FORMAT menu.

--
Rick B



Hanksor said:
I have a report that has a textbox named "Total2004" with a data source of
Total04. I would like to have the background color change if the value of
Total2004 is 0. Below is the code I have at this point, but all backgrounds
of total2004 change instead of just the ones with a value of 0.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Total2004].Value = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
End If
End Sub

Where am I going wrong? I'm using 97 so I don't have the use of conditional
formating.... Any help will be appreciated.

Thanx,
 
R

Rick B

Sorry. You did say that and I guess I ignored it. We were on 97 a couple
of years ago and finally went up to 2000. I feel your pain! I don't see
the problem with your code, but hopefully someone will jump in with a
solution.

Good luck,

--
Rick B



Hanksor said:
Because, as I stated in my post, We only have 97 here and I don't have the
built-in conditional formatting feature.
Rick B said:
Why are you using code? Use the built-in conditional formatting feature
that is in the FORMAT menu.
source
value
of
Total2004 is 0. Below is the code I have at this point, but all backgrounds
of total2004 change instead of just the ones with a value of 0.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Total2004].Value = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
End If
End Sub

Where am I going wrong? I'm using 97 so I don't have the use of conditional
formating.... Any help will be appreciated.

Thanx,
 
F

fredg

I have a report that has a textbox named "Total2004" with a data source of
Total04. I would like to have the background color change if the value of
Total2004 is 0. Below is the code I have at this point, but all backgrounds
of total2004 change instead of just the ones with a value of 0.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Total2004].Value = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
End If
End Sub

Where am I going wrong? I'm using 97 so I don't have the use of conditional
formating.... Any help will be appreciated.

Thanx,

If you change the color when a condition is met you must change it
back when the condition is not met.
Note: because Value is the control's default property, you do not need
to specifiy it.

If [Total2004] = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
Else
[Total2004].BackColor = vbWhite
[Total2004].ForeColor = vbBlack
End If

If you are just changing the back color, why are you including the
ForeColor in the code?
 
H

Hanksor

Thanks!!! I should have known that. Brain fart, I guess.... Thanks
again....
fredg said:
I have a report that has a textbox named "Total2004" with a data source of
Total04. I would like to have the background color change if the value of
Total2004 is 0. Below is the code I have at this point, but all backgrounds
of total2004 change instead of just the ones with a value of 0.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Total2004].Value = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
End If
End Sub

Where am I going wrong? I'm using 97 so I don't have the use of conditional
formating.... Any help will be appreciated.

Thanx,

If you change the color when a condition is met you must change it
back when the condition is not met.
Note: because Value is the control's default property, you do not need
to specifiy it.

If [Total2004] = 0 Then
[Total2004].BackColor = vbRed
[Total2004].ForeColor = vbBlack
Else
[Total2004].BackColor = vbWhite
[Total2004].ForeColor = vbBlack
End If

If you are just changing the back color, why are you including the
ForeColor in the code?
 

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