Link to home
Start Free TrialLog in
Avatar of bcarmi
bcarmi

asked on

Access 2010 - Conditional formatting on a Label

Hi,
On an Access 2010 report, I'm trying to change the behavior of a label (not a text box) to where if data is = 0 in another text box field, then the label changes color.
I'm fairly new to Access 2010 so your help is appreciated in advance.
thank you,
bcarmi
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
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
Where is this label (header, detail, footer)?

I don't know about 2010, but 2007 has a Format event associates with each of the above, and I'm sure this functionality is still there with 2010.  Use that event to change the backcolor of the label.

Private sub Detail_Format

    if [somefield] = "abc" Then
        me.YourLabelName.Backcolor = rgb(255, 0, 0)
   elseif [somefield] = "def" then
        me.YourLabelName.Backcolor = rgb(0, 255, 0)
   elseif [somefield] = "ghi" then
        me.YourLabelName.Backcolor = rgb(0, 0, 255)
   elseif [somefield] = "jkl" then
        me.YourLabelName.Backcolor = rgb(255, 255, 0)
   else
        me.YourLabelName.Backcolor = rgb(255, 0, 255)
   end if
End Sub

You could also use the Switch function, or possibly the Choose function (if the values of the field you want to test are continuous).

     

Avatar of bcarmi
bcarmi

ASKER

Hi,
Thank you for the swift reply.

fyed: The label is in the detail, but which event loads the page? I see "On click, format, dbl click, mouse down, mouse up, mouse move, paint, print, and retreat."

DatabaseMX: How do I go about emulating a Label with a text box? When I create textbox and put in an a value X, i get X is not a vaild field name or expression.

Thank you,
bcarmi
"When I create textbox and put in an a value X, i get X is not a vaild field name or expression."

In the text box Control Source, you need an expression"

="MyLabelCaption"

include the equals sign ... an surround the text with double quotes.

mx
If you want to use the Format event, click on the "Detail" bar that divides the header from the detail section.  Then view the Events tab on the Properties dialog and find the Format event.

Select [Event Procedure] from the dropdown on that line, then click the "..." to the right of that to view the VBA procedure.