Toggle Button setting Forecolor when null (1 Viewer)

TonyE

Registered User.
Local time
Yesterday, 23:12
Joined
Apr 11, 2019
Messages
19
i seem to have an issue when trying to set Toggle Button Forecolor when null, it just dosent seem to obey the command.

here is code which works fine for when Toggle = 0 or = 1, when null all works bar the "Me.ToggleTemplates.ForeColor = lngBlack" remains light gray, any idea why this is ?

Code:
lngBlack = RGB(41, 36, 33)
lngBlue = RGB(0, 191, 255)
lngGreen = RGB(50, 205, 50)
lngCyan = RGB(0, 255, 255)
lngRed = RGB(255, 0, 0)
lngSalmon = RGB(198, 113, 113)
lngYellow = RGB(238, 238, 0)
lngWhite = RGB(255, 255, 255)

If Me.ToggleTemplates = -1 Then
Me.ToggleTemplates.Caption = "Mode: View Templates"
Me.ToggleTemplates.BackColor = lngBlue
Me.ToggleTemplates.PressedColor = lngBlue
Me.ToggleTemplates.HoverColor = lngBlue
Me.ToggleTemplates.ForeColor = lngBlack
ElseIf Me.ToggleTemplates = 0 Then
Me.ToggleTemplates.Caption = "Mode: View Projects"
Me.ToggleTemplates.BackColor = lngGreen
Me.ToggleTemplates.PressedColor = lngGreen
Me.ToggleTemplates.HoverColor = lngGreen
Me.ToggleTemplates.ForeColor = lngBlack
ElseIf IsNull(Me.ToggleTemplates) Then
Me.ToggleTemplates.Caption = "Mode: View All"
Me.ToggleTemplates.BackColor = lngSalmon
Me.ToggleTemplates.PressedColor = lngSalmon
Me.ToggleTemplates.HoverColor = lngSalmon
Me.ToggleTemplates.ForeColor = lngBlack
End If
 
Last edited by a moderator:

isladogs

CID VIP
Local time
Today, 07:12
Joined
Jan 14, 2017
Messages
14,404
Post was moderated. i've added code tags so it is easier to read

As for your question, toggle buttons only have two states - true (-1) & false (0)
If you've done nothing to the toggle, its the default value - normally false
 

TonyE

Registered User.
Local time
Yesterday, 23:12
Joined
Apr 11, 2019
Messages
19
Not if you set Toggle button property "Triple Stare = Yes" then you do have a third state = Null. Its the third state that works ok for changing background colours but dosent seem to change the forecolor ?
 

June7

AWF VIP
Local time
Yesterday, 22:12
Joined
Mar 9, 2014
Messages
3,386
Null state only available for UNBOUND toggle (or checkbox or radio button).

It's either a bug or design that Null state sets font to a grey shade. Apparently it cannot be overridden.

Why do you need Null?

Instead of RGB codes could use VBA standard color constants.
vbBlack
vbGreen
vbBlue
vbRed
vbWhite
vbYellow
vbCyan
vbMagenta

Since you want text to be black in all cases, just set ForeColor in form design, no need for code (still won't override the Null state grey).
 
Last edited:

isladogs

CID VIP
Local time
Today, 07:12
Joined
Jan 14, 2017
Messages
14,404
I stand corrected.
However, with checkboxes, the triple state is only available for unbound controls.
Does that apply to toggle buttons as well?

I've done a quick test using your code & the only thing that changes is the toggle forecolor!
Caption etc unchanged.
May be best if you upload the form & any other required items for someone to look at

EDIT: June answered whilst I was checking the OPs comment
 
Last edited:

TonyE

Registered User.
Local time
Yesterday, 23:12
Joined
Apr 11, 2019
Messages
19
June7 posted indicating with third state = null, then cannot change forecolor ....... either by design or is a bug.

All else works so will have to live with the gray forecolour.

Also to answer June7 - I want a triple toggel to display a list box with different data - as my supplied code suggested three views:
"Mode: View Templates"
"Mode: View Projects"
"Mode: View All"

I use RGB coding since give more contol over colors used, the standard colors are sometimes just to bright.

thanks all for your inputs:)
 

June7

AWF VIP
Local time
Yesterday, 22:12
Joined
Mar 9, 2014
Messages
3,386
Don't think I've ever used toggle button. I would use a combobox or listbox or radio buttons in an OptionGroup.
 

TonyE

Registered User.
Local time
Yesterday, 23:12
Joined
Apr 11, 2019
Messages
19
Yeah I suppose could use combobox, listbox or radio buttons to acheive same goal.
 

isladogs

CID VIP
Local time
Today, 07:12
Joined
Jan 14, 2017
Messages
14,404
I would go for an option group with radio buttons.
Much simpler to code and IMO easier for the end user to understand
 

Users who are viewing this thread

Top Bottom