?
Solved

Access 2010 - Conditional formatting on a Label

Posted on 2010-11-15
5
Medium Priority
?
1,174 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
  • 2
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 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 49

Expert Comment

by:Dale Fye
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 49

Expert Comment

by:Dale Fye
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

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.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 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