Changing Text Colour

linanderson

Registered User.
Local time
Today, 14:37
Joined
Jul 13, 2002
Messages
17
Hello,

I have been looking at pasts threads concerning changing text colour in one field on a form, dependent on the value in this field.

The fields (from a query) calculates an age at retirement. If this age equals or is greater than 65, I would like to show the answer in red. If not the answer should be in the default black. At present I have no default value in the field and the associated retirement date and date of birth fields are not mandatory. The format is in "yy" and "mm".

I have experiemented but not been successful yet. Apologies, I am new to writing code.

If Me![AgeAtRetirement] >=65 Then
Me![Name].ForeColor = (255)
Else
Me![Name].ForeColor = (0)
End If

Also, where is the correct place to place this code. Before Update?
Any pointers welcome.
Thanks
 
Hiya,

Just a few tips:

1. Don't call fields Name, it confuses Access because it doesn't know whether you are referring to the value of the field or the name property of the form. This is because Name is a reserved word. Seems minor, consequences are major headache if you have to extend functionality in future.

2.Use the OnCurrent event of the form and the AfterUpdate event of the control:

If Me![AgeAtRetirement] >=65 Then
Me![Name].ForeColor = 255
Else
Me![Name].ForeColor = 0
End If

3.You can call one event from another, e.g.call the current event from the afterupdate and vica-versa,this means you don't have to type code twice.

4.Not sure if this relevant but you cannot conditionally change text colour in a query, you must build a form or report.

5.As I recall(sorry I'm an A97 luddite), that A2K has a conditional formatting option similar to excels version.

6.When building a report the code needs to go in the OnFormat event.
 
Thanks for getting back.

1. Name should have been AgeAtRetirement

2. Entered OnCurrent event on the form and AfterUpdate event of the control:

If Me![AgeAtRetirement] >=65 Then
Me![AgeAtRetirement].ForeColor = 255
Else
Me![AgeAtRetirement].ForeColor = 0
End If

4. Fine. It is the form which is based upon data in a query.

Problem is that the desired results are not working. All data is is normal colour and I receive a message 'Invalid Outside Procedure'. Am I missing anything?

Any further advice would be appreciated.
 
What version are you using. As Ian said, if you're using A2K you could use the Conditional Formatting tool which would make life a lot easier. If you're using 97, upgrade!

It's nice to see more people from my neck of the woods!
 
What exactly make purchasing A2k an "Upgrade"
Slower performance, ADO, more bugs, and those still there from 97?????
 
Maybe I should have finished my sentance with a ;)
 
It appears that the code is 'invalid outside procedure', which usually means you haven't put the code between the start and end of the sub procedure.

Check this example out, specific to your problem.
 

Attachments

Hello,

Thanks for getting back and the example.

I have now managed to get the correct results. My error was to keep the brackets around the colour numbers. I cannot believe I missed this.

Best regards..Linda
 

Users who are viewing this thread

Back
Top Bottom