473,569 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Bac kColor = vbGreen
End If
If Me.txtDivGL < -5 Or Me.txtDivGL > -8 Then
Me.txtDivGL.Bac kColor = vbYellow
End If
If Me.txtDivGL < -8 Then
Me.txtDivGL.Bac kColor = 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 8015
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******** *************@g 43g2000cwa.goog legroups.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.Bac kColor = vbGreen
End If
If Me.txtDivGL < -5 Or Me.txtDivGL > -8 Then
Me.txtDivGL.Bac kColor = vbYellow
End If
If Me.txtDivGL < -8 Then
Me.txtDivGL.Bac kColor = 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.Bac kColor = vbGreen
Case -5 to -7.99
Me.txtDivGL.Bac kColor = vbYellow
Case < -8
Me.txtDivGL.Bac kColor = vbRed
Case Else
Me.txtDivGL.Bac kColor = 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
8919
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 color. These text boxes need to go behind a single line of other bound text boxes (which show the actual record). I.e., the purpose of the unbound...
3
5921
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 terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both...
6
5495
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 row in green, all other rows just as they are normal. Is that possible ? regards Allan
4
3124
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 background colour. In A2000 it works great, but in A2003 the background doesn't always change and when it does it only changes when the record looses...
8
12027
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 expressions are the same for all controls Under some undetermined circumstances, when such subform is displayed, the controls on the subform start...
5
2359
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 have been working with the conditional
5
8951
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 on white, the third on gray etc etc.) I could write an expression based on the odd/even status of the primary key but this wont work when sorting...
1
4216
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 particular color you were using as a standard throughout your application, the only way to continue using that color is to code the color. Anyone...
3
2103
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. I am very green in this. Please help.
2
8608
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 an empty string. 1) Using Access: I select "Field value is" and "equal to". Not sure what to put in the Expression1 field. Have tried leaving it...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.