Full Version: Referencing Table Field Value To Change Back Color (with If/iif Vba/expression)
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
Heatshiver
I have a report where some field values will be blank at times. I would like to write an if statement (in VBA or as an expression) to state that if the field is blank, to change the back color of the field value on the report.

I can't seem to get it to work in either VBA or as an expression. In VBA I get a debugging error as to how I reference the table field value. In an expression (I am not sure how to refer to the back color of a field) I first tested with true returning "Good" and false returning "Bad". Even though the table field value is blank, it returns "Bad". I even tried to include IsNull(""), but this still returns "Bad". Even if I put a value in the table field and refer to that in the expression, it still returns "Bad" instead of "Good".

Can anyone provide me an example on how this would be done?

At the moment I don't have a date selection form before the report, but I have a record in the table that shows when switching the report to View mode.

Thank you!
BruceM
Have you tried conditional formatting?

QUOTE
In VBA I get a debugging error as to how I reference the table field value

What is the line of code that causes the error? In which event procedure have you placed the code?

QUOTE
I even tried to include IsNull("")

A zero length string (ZLS) is different than Null, which is essentially "unknown". The expression evaluates to False, since a ZLS is a known value, so it is not null.

QUOTE
I am not sure how to refer to the back color of a field

To refer to the back color of a control, Me.TextBoxName.Backcolor = vbYellow
You could also use the RGB function for the backcolor, if you want more flexibility than you can get from the VBA color constants such as vbRed, vbYellow, etc.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.