Link to home
Start Free TrialLog in
Avatar of ttist25
ttist25

asked on

Change Back Color of Rectangle in Query

Hello,

I have a microsoft access 2007 database with a report fed by a query.  I'm using iif statements to get values from the record and display text in text fields.

I would like to also use iif statements to change the Back Color of a rectangle on my report based on the value of a field.  

Here's an example of what I'm doing to display text:

iif(myTable.MyField_Description = "Value1",
"Text for value1.",
"Text for everything else.")
AS myTextBox,

That will display the appropriate text in myTextBox.

I would like to use the same thing to change the back color of a rectangle but I'm not sure of the syntax.  It would be something like this:

iif(myTable.MyField_Description = "Value1",
my.Rectangle.BackColor="#000000",
my.Rectangle.BackColor="#FFFFFF")
AS myRectangle,

FYI - if you haven't figured it out by now, I need to point out that I'm a serious noob with this stuff.  

TIA!
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Have you tried using conditional formatting?  Don't think that will actually work for a "rectangle", but you could create a textbox for the [MyField_Description] on the report, then use conditional formatting to test if the fieldvalue = "Value1" and if so use a conditional format.
ASKER CERTIFIED SOLUTION
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttist25
ttist25

ASKER

Ok - that gives me good ideas on the syntax of changing the color but, is it possible to do this inside my query without creating a sub?
"is it possible to do this inside my query without creating a sub? "

A query is like a table that displays data. I can't see a way to use a table to change bacground color without using an action statement.

The sub is there in the report, you only add the action statement to set the color on condition.
Avatar of ttist25

ASKER

Definitely not the most graceful solution I'm sure but, here's what I ended up doing:

I replaced the rectangle with a text box of the same size and shape
I used my iif statement as described above and set the text to either "On" or "Off"
Then I used the Conditional formatting toolbar thing to set the background fill and foreground font accordingly (either both gray or both white)

Works great!  Thanks for the help.  
Glad I could help.