VB to change box color from check field

travismp

Registered User.
Local time
Today, 17:36
Joined
Oct 15, 2001
Messages
386
(i posted this twice... i posted in forms first but then noticed the VB section... sorry)

I have a simple form with 3 check boxes. I want to write a vb code that will change the color of a box if a box is selected.

Table Name: tbl_main
Form Name: frm_color
Field Names: [check_red] [check_blue] [check_yellow]
Box Names: 'box_red' 'box_blue' 'box_yellow' (all currently translucent)

If someone checks the [check_red] field I want the 'box_red' to go from translucent background to a red background, and when unchecked to go back to translucent. Same with the Blue & Yellow boxes.

I have made a simple database and attached it for an example. Thank you all.
 

Attachments

There are many ways to do this.
Here's one, do this for each checkbox:
Code:
Private Sub check_red_Click()
    If check_red.Value = True Then
        Me.box_red.BackStyle = 1
        Me.box_red.BackColor = vbRed
    Else
        Me.box_red.BackStyle = 0
    End If
End Sub

You could just set all their colors and keep switching their transparencies. Or you could not touch their transparencies and just keep switching their colors.

Additionally code could be placed in each of the checkboxes' _afterupdate()

Hope this helps
 
Last edited:
I would do it as an options frame and use a case statement for value. This will be sleaker because you don't need code each checkbox.
 

Users who are viewing this thread

Back
Top Bottom