Access VBA to Change colour of cells in Report

Owain

New Member
Joined
Jun 9, 2004
Messages
34
Hi,

I'm trying to create a report within Microsoft Access 2000 and I would like to change the background colour of a box within a report based on the value returned.

The box is named "Progress_Percentage_Complete". Values in this box can range from 0 to 100. I am wanting the background colour to change as follows.

If value is 0 to 39 = red
40 to 59 = orange
60 to 79 = yellow
80 to 99 = light green
100= dark green

I gather that this can be done in VBA. However, I have very little experience in this area and wondered if anyone knows what code I would use to achieve the colour coding as detailed above. Also, where would I place this code within the report. Will it be found somewhere in the 'properties' of the Progree_Percentage_Complete Box?

Any help you can offer will be greatly appreciated!

Many thanks,

Owain.
:confused:
 
Very close, but Red is text so you have to tell Access that, using quotes. Try this:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Select Case [StatusT]
   Case Is = "Red"
        [Q1].BackColor = 255 'red
    Case Is = Blue
        [Q1].BackColor = 16711680 'blue
    Case Is = Black
        [Q1].BackColor = 0 'black
    Case Is = Green
        [Q1].BackColor = 32768 'green
End Select
End Sub
Denis
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Thanks Denis! that did it.
I also had to make sure that the "Back Style" property was set to "Normal".

Thanks,
 
Upvote 0

Forum statistics

Threads
1,215,255
Messages
6,123,896
Members
449,132
Latest member
Rosie14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top