Referring to object value in form detail paint event

highandwild

Registered User.
Local time
Today, 13:51
Joined
Oct 30, 2009
Messages
435
Hi All

I can set the various colors of an object in the detail section of a form using the paint event but I would like to set the foreground color based upon the value in the field referred to by the object or another fields value.

I thought that I could do it like this below but it does not work. I am sure that I am almost there. Thanks in anticipation.

Private Sub Detail_Paint()
Select Case Me.txtTown.Value
Case "Dorchester"
Me.Forename.ForeColor = 8179068
Case "Weymouth"
Me.Forename.ForeColor = 1030655
Case "Wimborne"
Me.Forename.ForeColor = 4349166
End Select
End Sub
 
I am not 100% sure, but i think the Paint event occurs before data is brought in. Even if this is not the case, your code would probably only apply 1 colour based on the first value it encounters, not each subsequent value.

My suggestion would be the use of conditional formatting, especially if you only have 3 towns/cities to worry about.
 
I was going down the right road Isskint.

The [Town] field did not have any data in it!!

It applies colors on any value, not just the first one.

Now I need to choose some acceptable background and foreground combination colors, the hardest job, as they will indicate the state / status of the data / record.

I would rather do it in code as then I could later provide a means by which users can choose their own colors.

Thanks
 

Users who are viewing this thread

Back
Top Bottom