Solved

Access 2010 - Conditional formatting on a Label

Posted on 2010-11-15
5
1,064 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 - Access MVP) earned 125 total points
Comment Utility
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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
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

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"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 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now