Change field color based on field value

  • Thread starter Thread starter Jen
  • Start date Start date
J

Jen

Guest
I am using Access 97. I'd like to create either a form or a report that will show field values in different colors depending on the field value. I'm assuming I'll have to use VBA for this. I've played around with it a bit, but can't get it to work correctly.

In the example below, I would like the negative amount to show up in red, but the others to be black. Is there a way in Access to do that? It doesn't matter to me if it is in a form or report.

Name Amt
Jones 1256
Smith 236
Johnson -568
 
Assuming it is in a form, and the field on the form is called txtAmt the code would look something like this.

if txtAmt<0 then
Me.txtAmt.Forecolor=255
end if

You could place this code in the lost focus event of the textbox.
 
Thanks for the suggestion, but I already tried that and it didn't work. It changed all of the records to the color. I'm using a continuous form. I did find another response on this site that appears if I stack text boxes on top of each, I will get the result I want.
 

Users who are viewing this thread

Back
Top Bottom