Expression for conditional formatting in form

Kai90

Board Regular
Joined
Jul 15, 2005
Messages
85
Hello,

I would like to conditionally format a text box on a form based on if the value entered is smaller or greater than a value on a table.


The table looks like this:

[Field1] [Field2] [Field3]

15______-6_______5
30______-2_______3
45______-1_______2
60_______1_______9

My conditional format would check the following: If value in text box ist smaller than the value in [Field2] on the table WHERE [FIELD1]=15, then color it red.


I am currently trying to use the conditional formatting on the text field with the following expression:
IIf([FORM1].[TEXTFIELD1]<[TABLE1].[FIELD2].[&FIELD1=15],True)

then it is supposed to color it red. However, something is missing or wrong in my expression.

Any ideas?
Thank you guys so much,

Kai
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
The fields need to be in the underlying query of the form.

And, you would refer to them in the conditional format by setting it to EXPRESSION IS and then (I am assuming that you were talking about field 2 comparing to field 3 where the first field is 15):

[FIELD2]< [FIELD3] AND [FIELD1] = 15
 
Upvote 0
Thank you so much for the answer.

My problem though is, that these fields (FIELD1,FIELD2 and FIELD3) are not in the underlying query of the form, but on a separate table ( a range table, so to speak) that is not connected to the form.

Is there no way to refer to this table? I found a microsoft.support page where they can look up and compare data to an external table using the dlookup funciton.

I am just trying to compare a value on the form (TEXTBOX1) to a value on the table [FIELD2] where a certain condition is met [FIELD1]=15.
 
Upvote 0
Thank you so much for the answer.

My problem though is, that these fields (FIELD1,FIELD2 and FIELD3) are not in the underlying query of the form, but on a separate table ( a range table, so to speak) that is not connected to the form.

Is there no way to refer to this table? I found a microsoft.support page where they can look up and compare data to an external table using the dlookup funciton.

I am just trying to compare a value on the form (TEXTBOX1) to a value on the table [FIELD2] where a certain condition is met [FIELD1]=15.

It may be possible to use a Dlookup in the conditional formatting but you can't just refer to the table like you had in the first post.

It might work if you have

Expression Is:

[TextBox1] < Nz(DLookup("Field2", "Table1", "[Field1]=15), 0)

But I'm not sure as a DLookup will return the first value that matches and if you have more field1 values of 15 then it wouldn't work. And also since tables aren't ordered sets you would need to provide a query with an OrderBy clause, instead of just referring to the table in the DLookup, so you get consistent results.
 
Upvote 0
Ok, I see where you are going.

Unfortunately, it is not working right now, so I created a query with the table's information in it. The "15" only occurs once in the query, so there should be no confusion on that part.

The conditional formatting is accepting the expression, but nothing happens...
 
Upvote 0
Yes, it is supposed to color the the box red if the condition were true.
I entered a value that is smaller than the looked up value, but nothing happens...
 
Upvote 0
Yes, it is supposed to color the the box red if the condition were true.
I entered a value that is smaller than the looked up value, but nothing happens...
Did you make sure you have a control to which you can move so that the control can be updated? If you remain in the control it won't be updated and hence it won't have a value that can be compared against.
 
Upvote 0
Yes, there are about 20 different text boxes on my form. Once I entered a value in the first control (the one where I am trying to apply this conditional formatting), I hit ENTER or TAB and move to the next control....
 
Upvote 0
It may be that Conditional Formatting doesn't work with unbound controls. I can't remember off hand.
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,600
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top