Trying to make some checkbox = true statements in access, that change the color of a

Shovell242

Registered User.
Local time
Today, 14:28
Joined
Jul 30, 2013
Messages
14
Hey guys,

I'm running into issues with trying to change the backcolor of a box within a form using VBA from check boxes.

Basically if a checkbox, or multiple check boxes are clicked I want the named box to turned gray.

I've been trying this method.

Code:
If checkbox1 = True Then
 
box1.BackColor = vbRed
 
Else
 
box1.BackColor = vbRed
 
End If
End Sub

However its not working. And i'm not quite sure to put the code in the form detail or the form itself.
 
At first glance, it appears as though that code should work.

I'd check to make sure that the back style is Normal, and not Transparent.

Also, (and this is probably a small oversight) make sure that you have your colors correct - in both cases above, if or else, you are changing the color to "vbRed".
 
Also, try adding "me" in front of the control name
Code:
If checkbox1 = True Then
 
[COLOR=red]Me.[/COLOR]box1.BackColor = vbRed
 
Else
 
[COLOR=red]Me.[/COLOR]box1.BackColor = vbRed
 
End If
End Sub
QUOTE]
 
Hey guys,

I'm running into issues with trying to change the backcolor of a box within a form using VBA from check boxes.

Basically if a checkbox, or multiple check boxes are clicked I want the named box to turned gray.

I've been trying this method.

Code:
If checkbox1 = True Then
 
box1.BackColor = vbRed
 
Else
 
box1.BackColor = vbRed
 
End If
End Sub

However its not working. And i'm not quite sure to put the code in the form detail or the form itself.

So just to clarify, you have a check box on your form and you are trying to dynamically change the background color of a shape when the text box is changed?

If so put your if statement in the OnClick event of the checkbox:

Code:
Private Sub checkbox1_OnClick()
If checkbox1 = True Then
    box1.BackColor = vbRed
Else
    box1.BackColor = vbRed
End If
End Sub
 
At first glance, it appears as though that code should work.

I'd check to make sure that the back style is Normal, and not Transparent.

Also, (and this is probably a small oversight) make sure that you have your colors correct - in both cases above, if or else, you are changing the color to "vbRed".

Boom you got it. Thanks so much!!
 
So just to clarify, you have a check box on your form and you are trying to dynamically change the background color of a shape when the text box is changed?

If so put your if statement in the OnClick event of the checkbox:

Code:
Private Sub checkbox1_OnClick()
If checkbox1 = True Then
    box1.BackColor = vbRed
Else
    box1.BackColor = vbRed
End If
End Sub

Yes you are correct.
 

Users who are viewing this thread

Back
Top Bottom