Solved

Microsoft Access - Conditional Formatting in Forms Not Working

Posted on 2013-11-01
16
2,854 Views
Last Modified: 2013-11-01
Hello Experts,

I am currently designing a form in MS Access.

The user selects a product and that product has a target output.  That target is displayed for the user on the form.

The user enters the actual output and I am trying to get the conditional formatting to colour either red or green, depending on whether the actual is greater or less than the target.

For some reason, the formatting is active, but sometimes incorrect.  Example -

Target - 2520 units per hour.  Anything equal to or above is green, anything below is red.

Actual - 100 (showing red - correct)
Actual - 29 (showing green - incorrect)
Actual - 2400 (showing red - correct)
Actual - 500 (showing green - incorrect)

Any idea as to why the rules are not being adhered to consistently?

Thanks,

diana_g
0
Comment
Question by:diana_g
[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
  • 5
  • 3
  • 3
  • +2
16 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39616909
The sorting is somehow working out alphabetically instead of numerically.  Try setting your Conditional Formatting using "Expression IS", and enter this as the expression:

CInt([YourFieldName]) => 2520

And set the colors appropriately.

Alternatively, force a similar conversion to integer in your form/report query.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39616916
what Data type are the field for the Actual Output and Target?

both should be Number..
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39616920
can you show show the conditional formatting, take a screen shot, and post that here as an image (last control on the toolbar)?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 61

Expert Comment

by:mbizup
ID: 39616935
Slight correction to my earlier comment  ( >= instead of =>), and if you are using a textbox on your form instead of a fixed integer value of 2520, use this for your conditional formatting expression:


CInt([YourFieldName]) >= CInt([YourTargetTextBoxName])
0
 

Author Comment

by:diana_g
ID: 39616971
Hello Experts,

Thank you for your suggestions.  @mbizup and @capricorn1 - I did try your suggestions, with no success.  Perhaps I have missed something.

Data type for the fields is a number.

Here is a screenshot.
Screenshot.bmp
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39616979
post the image of Conditional formatting you created


.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39616983
Since you have a mainform/subform setup, use this for the formatting expression:



CInt([YourFieldName]) >= CInt(Forms!YourMainFormName![YourTargetTextBoxName])
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39616987
not what I meant.  Open the form in design view, select the control with the formatting, the click the conditional formatting button on the ribbon.  Get a screen shot of the conditional formatting popup form so we can see precisely what the conditional format definition looks like.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39616988
Also, if the text "Units Per Hour" is actually included in the textbox data, use VAL instead of CInt:

CInt([YourFieldName]) >= Val(Forms!YourMainFormName![YourTargetTextBoxName])
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39616990
First...Make sure you first clear any existing CF on any and all of the individual controls

Then make sure you select all the control you want formatted *at the same time*, and set the conditional formatting for all of them this way...

This all works fine for me...
0
 

Author Comment

by:diana_g
ID: 39617049
Hello Experts,

To clarify, it is not a subform.  This is all on one form.

See attached for conditional formatting conditions.
Screenshot2.bmp
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39617063
Did you Try changing the Condition to "Expression Is", and using CInt() to force the values to integer?

The expression would be for the green:

CInt([YourFieldName]) >= CInt([TPR])

and for the red:

CInt([YourFieldName]) <  CInt([TPR])
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39617064
Again, this works fine for me, here is the output:
sample
and here is the CF:
CF
Note that all the controls are selected and the formatting rule is set for all of them only once.
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39617129
In the screenshot of your form, I believe you have the [TPR] field displayed in the upper right corner, but it is impossible to tell whether the 'units per hour' is part of the value of a field, or a label that simply follows the control.

Please confirm that the [TPR] control is bound to a field in the forms recordsource that is is a numeric data type.  If not you may want to try:

>= Val(Forms!YourMainFormName![YourTargetTextBoxName])

or, as mbizup mentioned above,  change the test from "Field value is" to "Expression is"  and set the expression as she described it above.

CInt([One]) >= CInt(Forms!YourMainFormName![TPR])
CInt([Two]) >= CInt(Forms!YourMainFormName![TPR])
...
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 39617241
Please investigate the other experts posts first, I think they are on to something...

FWIW, here is the simple sample I created that had his working...
Database184.mdb
0
 

Author Closing Comment

by:diana_g
ID: 39617892
Thank you @mbizup.  This solution worked very well.  Thank you to all the other experts for your feedback.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 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