Solved

Microsoft Access - Conditional Formatting in Forms Not Working

Posted on 2013-11-01
16
2,598 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
  • 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 119

Expert Comment

by:Rey Obrero
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
 
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 119

Expert Comment

by:Rey Obrero
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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.

895 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