Trying to change ForeColor accordingly

  • Thread starter Thread starter Gina
  • Start date Start date
G

Gina

Hi .

I would like to set a date to be red if MOT is due this month and yellow if
next month.otherwise leave it black

but doesn't work ... why ???
(put it in the Form_GotFocus event as well ) same result ... no change of
color

Thanks for any advice what to do
Gina

____________________________________________________
Private Sub Form_Current()

If Form__frmCar.MOT<> Null Then

If Month(Form__frmCar.MOT) > Month(Date) + 1 Then
Form__frmCar.MOT.ForeColor = RGB(255, 0, 0)
ElseIf Month(Form__frmCar.MOT) > Month(Date) + 2 Then
Form__frmCar.MOT.ForeColor = RGB(255, 255, 0)
Else
Form__frmCar.MOT.ForeColor = RGB(0, 0, 0
End If

End If

End Sub
______________________________________________________
 
Just use the built-in conditional formatting. No need to build complex code
for a built-in function.

Rick B
 
The problem is with this line:
If Form__frmCar.MOT<> Null Then
which always evaluates to False, and so the code never runs.

Try:
If Not IsNull(Form__frmCar.MOT) Then

For an explanation of why you cannot compare anything to Null, see:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

BTW, if you are working in A2000 or later, it may be more efficient to do
this with conditional formatting.
 
Hi Rick.

Thanks for your answer ...
of course you are right ... why building any code if the function is already
there.

but where is this function and how to apply it ???
unfortunately I don't know about these functions ... maybe you can give me a
hint

thanks,
Gina
 
Thanks Allen, worked immediately !!!!

Gina :)


Allen Browne said:
The problem is with this line:
If Form__frmCar.MOT<> Null Then
which always evaluates to False, and so the code never runs.

Try:
If Not IsNull(Form__frmCar.MOT) Then

For an explanation of why you cannot compare anything to Null, see:
Common errors with Null
at:
http://allenbrowne.com/casu-12.html

BTW, if you are working in A2000 or later, it may be more efficient to do
this with conditional formatting.
 
Back
Top