?
Solved

Microsoft Access - Conditional Formatting in Forms Not Working

Posted on 2013-11-01
16
Medium Priority
?
3,129 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 48

Expert Comment

by:Dale Fye
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 48

Expert Comment

by:Dale Fye
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 2000 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 48

Expert Comment

by:Dale Fye
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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 …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

777 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