Color Bar

Color Bar
How do I program MS Access to show a color bar on each record corresponding to a number in a field?

The number is the time remaining for a delivery to be made. I want the color go from green to yellow to red as time runs out and goes negative.

On the form, create a box using the rectangle tool. Name it bxColorBar (or whatever you choose). Set the following properties for the rectangle:

Back Style: Normal
Special Effect: Flat
Border Style: Solid
Border Color: 0
Border Width: 1

In the form’s VBA code module, use the Form Load event (or the Activate event) … the choice of which event you use is up to you and how your application works.

If the number you’re using is a calculation (Delivery Date – Current Date) where the result is an integer, then something like the following would be used:

Private Sub Form_Load()

Dim intDays As Integer

intDays = [Delivery Date] – Now()

Select Case intDays
Case Is <= 0
bxColorBar.BackColor = vbRed
Case 1 To 5
bxColorBar.BackColor = vbYellow
Case Is >= 6
bxColorBar.BackColor = vbGreen
End Select

End Sub

You can contact me through my profile if you have any questions.

Good luck!

color bar

Leave a comment

Your comment