Problem: Coding conditional formats returns different (inaccurate) results then when using the built in conditional formatting functionality (via the menu).
In Access on a datasheet form, when I create multiple formatting conditions for a field using the 'Conditional Formatting...' option on the field's menu, all the conditions work as expected. However, when I code the same conditions in the On Open event, it only responds(changes font color) to the 'GreaterThan' condition. This seems to only impact a Date field where the conditions are comparing the field's date to the date condition (today's date - using the DATE function).
For example, using the menu option to format the conditions, I create these 2 conditions:
Condition 1: Field Value Is : Greater Than : Date()
If condition 1 is met, turn font color Yellow.
Condition 2: Field Value Is : Less Than : Date()
If condition 2 is met, turn font color Red.
Each condition changes the text color (Yellow or Red) for fields with date values 'Greater Than' or 'Less Than' the current date. This all works fine since I added conditions directly in the field itself.
Now, I want to change the conditions using code instead. I've coded the 'On Open' event of the datasheet form to delete the pre-existing conditions, then add new conditions. The problem is that when it runs, it changes ALL every records field colors to the 'greater than' condition color (Blue in this case) and none to the 'less than' condition even though several records meet the 'less than' criteria condition. I've tried rearranging the condition order, using actual dates (ie, #08/24/05#) instead of the DATE function, but nothing works for any other date conditional formatting except when I use the 'Greater Than' operator!
Here is the code in the On Open event:
Private Sub Form_Open(Cancel As Integer)
Dim objFrc As FormatCondition
[fldFormat].FormatConditions.Delete
Set objFrc = Me![fldFormat].FormatConditions.Add(acFieldValue, acLessThan, Date)
Me![fldFormat].FormatConditions(0).ForeColor = 4227072 ' green
Set objFrc = Me![fldFormat].FormatConditions.Add(acFieldValue, acGreaterThan, Date)
Me![fldFormat].FormatConditions(1).ForeColor = 16711680 ' blue
End Sub
The form opens with no errors. Even though both conditions are there for 'Greater Than' or 'Less Than', it paints ALL records date values BLUE which is the 'Greater Than' condition even though several records don't meet that condition!
Also, I tried the same operator using a text field and again, only the 'Greater Than' condition format is recognized and all records 'appear' to meet only that condition, not any others ??
Any idea's??
Thanks, flize
In Access on a datasheet form, when I create multiple formatting conditions for a field using the 'Conditional Formatting...' option on the field's menu, all the conditions work as expected. However, when I code the same conditions in the On Open event, it only responds(changes font color) to the 'GreaterThan' condition. This seems to only impact a Date field where the conditions are comparing the field's date to the date condition (today's date - using the DATE function).
For example, using the menu option to format the conditions, I create these 2 conditions:
Condition 1: Field Value Is : Greater Than : Date()
If condition 1 is met, turn font color Yellow.
Condition 2: Field Value Is : Less Than : Date()
If condition 2 is met, turn font color Red.
Each condition changes the text color (Yellow or Red) for fields with date values 'Greater Than' or 'Less Than' the current date. This all works fine since I added conditions directly in the field itself.
Now, I want to change the conditions using code instead. I've coded the 'On Open' event of the datasheet form to delete the pre-existing conditions, then add new conditions. The problem is that when it runs, it changes ALL every records field colors to the 'greater than' condition color (Blue in this case) and none to the 'less than' condition even though several records meet the 'less than' criteria condition. I've tried rearranging the condition order, using actual dates (ie, #08/24/05#) instead of the DATE function, but nothing works for any other date conditional formatting except when I use the 'Greater Than' operator!
Here is the code in the On Open event:
Private Sub Form_Open(Cancel As Integer)
Dim objFrc As FormatCondition
[fldFormat].FormatConditions.Delete
Set objFrc = Me![fldFormat].FormatConditions.Add(acFieldValue, acLessThan, Date)
Me![fldFormat].FormatConditions(0).ForeColor = 4227072 ' green
Set objFrc = Me![fldFormat].FormatConditions.Add(acFieldValue, acGreaterThan, Date)
Me![fldFormat].FormatConditions(1).ForeColor = 16711680 ' blue
End Sub
The form opens with no errors. Even though both conditions are there for 'Greater Than' or 'Less Than', it paints ALL records date values BLUE which is the 'Greater Than' condition even though several records don't meet that condition!
Also, I tried the same operator using a text field and again, only the 'Greater Than' condition format is recognized and all records 'appear' to meet only that condition, not any others ??
Any idea's??
Thanks, flize