Please help on conditional formatting

  • Thread starter Thread starter Al
  • Start date Start date
A

Al

Can someone give me an example on how to use a function
written in a module, in the conditional formatting.
for example: I want to change the color of a field in the
datasheet based on the day of the day of the week,day of
the month,and month of the year.I tried to put an
expresion (for the day and the month)directly into the
conditional formatting and it worked but when I tried to
add the year I could not due to the fact that it limits
the text typed to 255 character,I think? can I use a
function instead and then use the function name within the
conditional formatting?
thanks
Al
 
Al said:
Can someone give me an example on how to use a function
written in a module, in the conditional formatting.
for example: I want to change the color of a field in the
datasheet based on the day of the day of the week,day of
the month,and month of the year.I tried to put an
expresion (for the day and the month)directly into the
conditional formatting and it worked but when I tried to
add the year I could not due to the fact that it limits
the text typed to 255 character,I think? can I use a
function instead and then use the function name within the
conditional formatting?
thanks
Al

Sure. Just create the function in either the form's module or a
standard module, and have it return some simple value that your
conditional formatting expression can use. If you need help, post the
expression you're trying to use, along with a description of what you
want it to do, and we may be able to help you out.
 
Here is an example of the function:
*************************************************
Private Function StatusColor() As Integer
If Me![ActionCategory] = "Weekly Reports" And [parent].
[Statuslbl] = "2 Days to the weekly report!" Then
StatusColor = 1
End If
End Function
******************************************
how do I place this into the conditional formatting. I
tried (expresion) statuscolor = 1, but it did not work
I am trying to change the color of a record in a data
sheet subform based on the criteria above. It worked well
when I added the code in the if statment, without the if
end if, directly in the conditional formatting. However,
when I wanted to add more criteria it would not let me
type after I reached about 255 character. that is why I am
trying the function route. Another question, would it
accept a procedure instead of function and can you show me
how.
thanks
Al
 
Al said:
Here is an example of the function:
*************************************************
Private Function StatusColor() As Integer
If Me![ActionCategory] = "Weekly Reports" And [parent].
[Statuslbl] = "2 Days to the weekly report!" Then
StatusColor = 1
End If
End Function
******************************************
how do I place this into the conditional formatting. I
tried (expresion) statuscolor = 1, but it did not work
I am trying to change the color of a record in a data
sheet subform based on the criteria above. It worked well
when I added the code in the if statment, without the if
end if, directly in the conditional formatting. However,
when I wanted to add more criteria it would not let me
type after I reached about 255 character. that is why I am
trying the function route. Another question, would it
accept a procedure instead of function and can you show me
how.

It has to be a function. When you entered the expression for the
conditional format, did you include the parentheses after the function
name? You have to put in the parentheses to let Access know that this
is a function:

Expression Is StatusColor()=1

In a simple test, this works for me.
 
I'd like to backup a bit. Is this how you would "colour" a line in a form
in continuous mode?

field1 field2 <---green text
field1 field2 <--- red text due to some criteria
field1 field2 <--- green text

If so, how/where do you enter this formatting? When I have tried to create
code to colour fields in a continuous mode form, ALL the lines were coloured
based on only the first line in the recordset.

Can you please explain how this is done?

Thank
Alan S.
 
Alan said:
I'd like to backup a bit. Is this how you would "colour" a line in a
form in continuous mode?

field1 field2 <---green text
field1 field2 <--- red text due to some criteria
field1 field2 <--- green text

If so, how/where do you enter this formatting? When I have tried to
create code to colour fields in a continuous mode form, ALL the lines
were coloured based on only the first line in the recordset.

Can you please explain how this is done?

Thank
Alan S.

It was very difficult to do in Access 97 or before. With Access 2000
and the introduction of Conditional Formatting, it became quite easy
(most of the time). There are quirks in CF, but basically it works.

The problem you experienced is classic for continuous forms -- there's
really only one of each control in the detail section, just painted
multiple times, so when you change any of its properties (such as
ForeColor or BackColor), you change that property for all the displayed
copies of that control. With Conditional Formatting, you select the
control in design view, then click Format -> Conditional Formatting...
on the menu bar. At that point you are presented with a dialog that
lets you set up to three sets of conditional format attributes and the
criteria under which they will be applied. For more information, search
the help file for "Conditional Formatting".
 
Back
Top