View Full Version : Expression Help! Color changes in fields!


sp00k
02-05-2009, 09:03 AM
So basically I have a report about vehicles. I have the name of the vehicle and the color of the vehicle. But I want the vehicle name background be the same color as the color field. I can't seem to get the color logic down.

Any help?

HiTechCoach
02-05-2009, 09:26 AM
So basically I have a report about vehicles. I have the name of the vehicle and the color of the vehicle. But I want the vehicle name background be the same color as the color field. I can't seem to get the color logic down.

Any help?

First, make sue the control's Back Style is set to Normal.

In the section witht he contrl use the On FOrmat event.

Example:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Me.VehicleName.BackColor = vbBlue

End Sub

From the help file:


Color Constants


The following constants can be used anywhere in your code in place of the actual values:

Constant Value Description
vbBlack 0x0 Black
vbRed 0xFF Red
vbGreen 0xFF00 Green
vbYellow 0xFFFF Yellow
vbBlue 0xFF0000 Blue
vbMagenta 0xFF00FF Magenta
vbCyan 0xFFFF00 Cyan
vbWhite 0xFFFFFF White




To make it easier, I would add a field to the table to store the color and use a Color Picker to allow the user to pick the color and srote it in the table.

Then your code woudl be as simple as:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Me.VehicleName.BackColor = Me.VehicleColorCode

End Sub

sp00k
02-05-2009, 09:32 AM
Thanks, i will give that a go(I like the color picker example!) I haven't used VB coding too much though. Is there anyway to use the expression builder? or should this be pretty straight forward?

dkinley
02-05-2009, 09:36 AM
Just to add to Hi-Tech's ...

If you want more colors you can use a 6-digit color, too. Unless you're good at translation, I'd suggest doing a search for "colortranslator2000.mdb". This was written do to conversions to assign the right color the first time around.

For instance, if you sampled a color in a program and retrieved the RGB or HTML settings - it will give you the MS Access 6-digit equivalent.

-dK