Question : How can I change the colour of text in a report field to match a colour specified in the report?

I have a database to maintain a small vehicle fleet.  In the Vehicles Table are details of each vehicle, ie. Make, model, body, colour, etc...  I also have a Colours Table which has two fields, Colour & Code (the code being the Microsoft code for colours).  Naturally the Vehicles table is linked to the Colours table via their respective Colour fields.

There is a Report that outlines assorted vehicle usage information and I would like the vehicle details in the Header section of the report to be presented in the colour that matches the colour of the vehicle ([Colour] field), with the exception of white vehicles which I will have to be presented in black text.

As there are more than seven vehicles I can not use either Conditional Formatting or an iif(... statement.
Can someone tell me how I can do this?

Answer : How can I change the colour of text in a report field to match a colour specified in the report?

This can really be done easily in the detail's "format" event. Let's say the text is in txtDetails, and you have the colour in txtCode. It needs to be present on the report even if the text box is not visible.

Right-click the section and choose "build event". Add the one line of code below between the existing "Private Sub... / End Sub" lines.

Good luck!
(°v°)
1:
2:
3:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    txtDetails.ForeColor = txtCode
End Sub
Random Solutions  
 
programming4us programming4us