Solved

Access 2010 - Conditional formatting on a Label

Posted on 2010-11-15
5
1,117 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:bcarmi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 125 total points
ID: 34139607
The easiest way to do this would be ... to use a Text box to emulate the Label, then use Conditional Formatting in the text box to change the color ... based on the condition in the other text box.

mx
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 34139683
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).

     

0
 

Author Comment

by:bcarmi
ID: 34139942
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
0
 
LVL 75
ID: 34139978
"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
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 34140258
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question