I'll be honest, I haven't got a clue as to what you're trying to do with this code, and I suspect by the lack of responses that no else does either. But this kind thing is easily done using Conditional Formatting, assuming you're running Access 2000 or later.
- In Form Design View, click on the textbox to select it
- Goto Format - Conditional Formatting and set up the boxes as:
- "Field Value Is" "Less Than" Date()
- Now, set the font/forecolor to Red
- Click "OK"
Linq ;0)>
Thanks for responding missinglinq. I'm sorry that my post was so confusing. I think, sometimes, longer posts get less attention because folks don't have the time to wade through a ton of irrelavent details. So I try to keep my posts as short as possible so I don't waste people's time. I guess my brevity came at the expense of clarity. My apollogies.
For the problem I'm having, I'm already using the conditional formating. However, instead of using the conditional formatting dialog box by right-clicking on the textbox while the report is in design view, I was setting up the conditional formatting using code in the report's OnOpen event. My report actually has a dozen or more textboxes that I want to set up the exact same conditional formatting. So it seemed to me to be more efficient to use VB code to do it.
In the code I provided earlier, Ctrl1 is the generic name of a textbox on the report. CFO is the name of a FormatCondition object. The following line of code creates a new condition for the textbox:
- Set CFO = Ctrl1.FormatConditions.Add(acExpression, , "[" & Ctrl1.Name & "] < Date()")
I named the textbox (Ctrl1) the same as the control source field (which is a date/time field type). Thus, the third argument of the line of code above should be evaluated as "[Ctrl1] < Date()" where the value of Ctrl1 is some date.
The next line of code sets the text color to red if the condition above is true:
- CFO.ForeColor = RGB(255, 0, 0)
To me, this fairly simple and straight forward. However, like I said earlier, Access is evaluating the condition in some unknow manner. I say this because when my report runs the text for some records where the value of Ctrl1 is before today is not turned red (even though it meets the condition Ctrl1 < Date() ) and the text for some records where the value of Ctrl1 is later than today is turned red.
I wanted some help to figure out how Access is evaluating the condition "Ctrl1 < Date()" so I can adjust the syntaxt to get the result I desire (any date before today is shown in red text).
I'm sorry if I've been too long winded. I'm just trying to avoid confusing folks, again.
Thanks again for your help.