473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Conditional Format With VBA

I cant seem to get this to work! Basically, what I want to do is
format some text boxes bases on the following:
0 to -4.99% = Green

-5.00 to -7.99 = Yellow
< -8.00 = Red

I have used the following code:

If Me.txtDivGL > 0 Or Me.txtDivGL < -5 Then
Me.txtDivGL.BackColor = vbGreen
End If
If Me.txtDivGL < -5 Or Me.txtDivGL > -8 Then
Me.txtDivGL.BackColor = vbYellow
End If
If Me.txtDivGL < -8 Then
Me.txtDivGL.BackColor = vbRed
End If

Why doesn't this work? It always comes up with the wrong color. The
value of the text box is based on a lookup from a table and then
formatted as a percent.

Please help as I am clueless as to why this won't work.

Nov 13 '05 #1
2 8002
Hmm... this is an odd way of expressing your rule. That's probably why
it won't work.

How about using a case statement? the problem is that your ranges
overlap. Express the rule this way:
From <start value> to <stop value>

Color = <some color>

I'm not even going to try to figure out what your code is supposed to
do. What I'm getting at is this - express it in plain English first -
for yourself as much as people trying to help you. Once you do that,
coding it is pretty simple.

or look up Select Case in the VBA help

Nov 13 '05 #2

"Jason" <ja*****@sw.rr.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
I cant seem to get this to work! Basically, what I want to do is
format some text boxes bases on the following:
0 to -4.99% = Green

-5.00 to -7.99 = Yellow
< -8.00 = Red

I have used the following code:

If Me.txtDivGL > 0 Or Me.txtDivGL < -5 Then
Me.txtDivGL.BackColor = vbGreen
End If
If Me.txtDivGL < -5 Or Me.txtDivGL > -8 Then
Me.txtDivGL.BackColor = vbYellow
End If
If Me.txtDivGL < -8 Then
Me.txtDivGL.BackColor = vbRed
End If

Why doesn't this work? It always comes up with the wrong color. The
value of the text box is based on a lookup from a table and then
formatted as a percent.

Please help as I am clueless as to why this won't work.


With that code it looks to me as though it would never be green. If the
value is -8 or greater it would be yellow, less than -9 red.

How about something like:

Select Case Me.txtDivGL
Case 0 to 4.99
Me.txtDivGL.BackColor = vbGreen
Case -5 to -7.99
Me.txtDivGL.BackColor = vbYellow
Case < -8
Me.txtDivGL.BackColor = vbRed
Case Else
Me.txtDivGL.BackColor = somerrorcolor
End Select

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Kreps | last post by:
(acc 2002) I've got six unbound text boxes on a subform that has a white background. Each of those six boxes has an expression that when true, will change its background from white to another...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
6
by: Allan Koch | last post by:
Dear NG, I would like to format a record in a subform, dependent on a value in one field. If one field in the record I show in a subform (datasheet view) is true I like to view that particular...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
8
by: Dimitri Furman | last post by:
Given: Access 2002/2003 A subform in datasheet or continuous view, placed on a tab page (this last may or may not matter) Conditional formatting applied to some controls on the subform - format...
5
by: John Baker | last post by:
Hi: I have a field that i wish to use the conditional format capability on, and for some reason it wont work. The field is a a text box: =- I would like to make it red when negative, and...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
1
by: dddsssdddsss | last post by:
A comment and a question To anyone who is using conditional formatting, beware that in Access 2007 the color pallette is not the same as the color pallette in Access 2003. So if you have a...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
2
by: Lyn | last post by:
Hi, Having fun trying to get Conditional Formatting working on a textbox control in a continuous form subform (Access 2003). The condition I want is when the value of the textbox is Null and/or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.