Solved

Microsoft Access - Conditional Formatting in Forms Not Working

Posted on 2013-11-01
16
2,509 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
Comment Utility
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
Comment Utility
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)
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
post the image of Conditional formatting you created


.
0
 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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)
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 61

Expert Comment

by:mbizup
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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)
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you @mbizup.  This solution worked very well.  Thank you to all the other experts for your feedback.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

762 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

10 Experts available now in Live!

Get 1:1 Help Now