External References in Conditional Formatting Expressions.
Normally, we use a Form/Report TextBox value in Conditional Formatting expressions to set a control's font or Background color.
For example:
FIELD VALUE IS BETWEEN 1 and 10 - whatever formatting you define will be displayed on the selected field, provided the field value is between 1 and 10.
OR
FIELD HAS FOCUS – the conditional formatting becomes visible when the field becomes active.
OR
EXPRESSION IS [ID]=5 OR [LastName] = "Nancy" – formatting is applied to a field, depending on the current values of two other fields used in the expression.
The key values in capital letters are selected from a drop-down control on the Conditional Formatting Dialog Control. Use the last example of our new method as a reference, and see how it can be used differently.
In the above expression, both [ID] and [Last Name] controls are on the same Form/Report and refer to the current record values of the Form/Report. This is the normal procedure.
A Different Approach.
Keep in mind that the values referenced in an expression don’t always have to come directly from the current form or its record source. They can also be pulled from other sources:
From a control on another open form.
From a field in a different table (or query).
When it comes to tables, you don’t need to keep them open to use their values. Instead, you can rely on the DLookup() function, which allows you to fetch a value directly from a table or query field within your expression.
For example:
=DLookup("[MaxMarks]","tmp_MaxMarks")
This will retrieve the MaxMarks value directly from the tmp_MaxMarks table.
This flexibility allows you to combine data from multiple sources—current forms, other forms, and tables—into a single expression that drives your chart or calculation.
When the above example was written with an external field reference, it looks like the expression given below.
EXPRESSION IS Forms![Orders]![OrderID] = Dlookup("Order_ID","tbl_OrderParam")
Assume that the above Conditional Formatting expression is written in a Field (say the Amount field) of frm_myForm.
If the current record OrderID value of the Orders Form (the second form in open mode) and the Order_ID value of the tbl_OrderParam Table (the expression assumes that the Parameter Table has only one record in it) match, then apply the defined conditional format on the active Form's (frm_myForm) Amount Field.
Experiment yourself and find out how it works.










[…] MS-ACCESS TIPS AND TRICKSLEARN MS-ACCESS TIPS AND TRICKS body.custom-background { background-image: […]
ReplyDelete