Using a toggle button to change a label colour (1 Viewer)

atrodden

Registered User.
Local time
Today, 00:05
Joined
Jan 23, 2014
Messages
15
Hello all,

Is it possible to use a toggle button to change the colour of a label?

I assume the code should be something like this:

Code:
If Me.ToggleButton = 1 Then
Label.BackColor = RGB(0, 255, 0)
ElseIf Me.ToggleButton = 0 Then
Label.BackColor = RGB(255, 255, 255)
End If

But I've tried it in the "On Click" sections and it doesn't work.

Thanks in advance
 

pr2-eugin

Super Moderator
Local time
Today, 00:05
Joined
Nov 30, 2011
Messages
8,494
Are you sure it is BackColor and not ForeColor? Also try debugging the code, see if the Click method is called, if so what is the value returned by the ToggleButton?
 

atrodden

Registered User.
Local time
Today, 00:05
Joined
Jan 23, 2014
Messages
15
Yeah its definitely the back colour

Also try debugging the code, see if the Click method is called..

I don't what you mean by this though? :confused:

The toggle button has a value of either 1 or 0 though, with a Yes/No column in a table as its control source.
 

pr2-eugin

Super Moderator
Local time
Today, 00:05
Joined
Nov 30, 2011
Messages
8,494
So, if you change the code as,
Code:
If Me.ToggleButton Then
    Label.BackColor = RGB(0, 255, 0)
Else
    Label.BackColor = RGB(255, 255, 255)
End If

Some Tips on Debugging in VBA
 

atrodden

Registered User.
Local time
Today, 00:05
Joined
Jan 23, 2014
Messages
15
Still not working :(

If I use a macro then the label changes colour when the toggle is pressed but it reverts back when you leave the form and re-enter it.
 

nanscombe

Registered User.
Local time
Today, 00:05
Joined
Nov 12, 2011
Messages
1,082
Is the Back Style property of the Label set to Transparent rather than Normal?

If it is set to Transparent then it won't matter what colour you make it you would still see the colour of the form instead.
 

Users who are viewing this thread

Top Bottom