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!

How to change field backcolor based on field contents

Status
Not open for further replies.

RonQA

Technical User
Jun 24, 2007
61
US
I have a report that is based on a query. on that report is a subreport based on a query. I need to take the (10) resulting fields from the subreport and change the colors based on thier numerical value. With the code below it changes all the fields of the subreport. How do i isolate only certain fields?

If [CumPct].Value < 0.12 Then
[CumPct].BackColor = vbRed
End If


Thanks,
 
Use conditional formatting. You shouldn't need to write a single line of code.

BTW: If you really want to use code, you must have and Else to switch the BackColor back to white.
Code:
If [CumPct].Value < 0.12 Then
    [CumPct].BackColor = vbRed
  Else
    [CumPct].BackColor = vbWhite
End If

Duane
Hook'D on Access
MS Access MVP
 
The conditional formatting only gives you three and is there anyway to call out the individual fields which there are 10 of?

Thanks for your response.
 
You should be referencing "controls", not "fields". I don't know anything about what you want to do with 10 of something. Does your expression involve 10 somethings or do you want to change properties of 10 somethings?

Duane
Hook'D on Access
MS Access MVP
 
I have a report that has a subreport in it. The subreport is the result of a query.

The results of the query lists (10) records in (3)columns.

In each row of the record I want to change the rows color if the last field meets a a value.


Hope that helps.
 
It would be easier to understand if you stated something like:
I would like the background of the detail section of my report to change to red if the bound control, CumPct has a value < 0.12.

You might try code in the On Format event of your section like:
Code:
    Me.Section(0).BackColor = IIf(Me.CumPct < 0.12,vbRed,vbWhite)

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top