I know you can have triple state check boxes in Access but I don’t see a way to have this in VB. I want to have a ‘true’, ‘false’ or ‘not selected’ (greyed out) status.
Anyone know how to do this? Do I need to get a 3rd party control?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Triple State Checkbox (VB6)
VB does not act at all like Access. If you have a CheckBox, it can have a value of vbChecked or vbUnchecked (corresponding to checked or not), plus it has an Enabled property which is either True or False (corresponding to grayed-out or not), so it it like a QuadState! See this thread for some more info on transition from Access to VB.
Try this example: put an array of four checkboxes on a new form along with a single command button and enter this code:
Option Explicit Dim InCheckEvent Private Sub Check1_Click(Index As Integer) If InCheckEvent Then Exit Sub InCheckEvent = True Check1((Index +1) Mod 4).Enabled = True Check1((Index+1) Mod 4).Value = vbUnchecked Check1((Index +2) Mod 4).Enabled = False Check1((Index+2) Mod 4).Value = vbChecked Check1((Index +3) Mod 4).Enabled = False Check1((Index+3) Mod 4).Value = vbUnchecked DoEvents InCheckEvent = False End Sub Private Sub Command1_Click() Dim cb As CheckBox InCheckEvent = True For Each cb in Check1 cb.Enabled = True cb.Value = vbUnchecked Next cb InCheckEvent = False End Sub
You are absolutely correct, Rory! I never knew it, but there is a vbGrayed. If you set the Value of a checkbox to vbGrayed, it is checked and dimmed and the Enabled property is unchanged, so a checkbox can have six different states.
Now I have a question, what use is a dimmed checkbox and what does a user do to dim a checkbox?
Never having used VB proper, only VBA, I couldn’t say for sure but I assume it’s the same as an Access triplestate checkbox – you have Yes/No/Unspecified(Null in Access). If you don’t want a default value for a checkbox, you’d set its triplestate property to true and then you know whether it was specifically UNchecked rather than ignored. I may, of course, be entirely wrong!
I don’t think there is actually a way for a user to dim it other than not touching it at all.
**Edit**
Not sure what I was thinking of – in Access at any rate, clicking on a triplestate checkbox cycles through all three possible states. Perfect for Yes/No/Don’t know questionnaires!
Having had a chance to check out the VB Checkbox, it can have one of 3 possible value initially, but once clicked can then only alternate between True and False.
It seems it cannot be given any value other tan 0 or 1 from code, and 2 (Grayed) has to set at design time.
So I would suggest the best use for it is to accept a global default if left in grayed state, otherwise True or False to apply a specific value.
VBA Checkboxes do cycle through 3 possible values if set to TripleState, Null, 0 and 1
Andrew C
There’s been a lot of discussion on how to do this and not a single question as to why. The null state of a checkbox normally indicates that it hasn’t been touched, which is why you can’t cycle through the states easily. True or False indicate that a value has been set. What are you trying to achieve with a triple-state checkbox anyhow?
The reason I wanted a triple state check box is for when users set options to download data from a datasource – e.g. if there is a boolean field ‘sold’ , I want to be able to select items that are set to TRUE (check box TRUE), FALSE (check box FALSE), or both (check box unselected).
So basically I want to be able to select true, false or either – like you can do in Access.
Thanks
Here is the click event that you need to cycle:
Option Explicit Dim InCheckEvent As Boolean Dim Check2Value As CheckBoxConstants Private Sub Check2_Click() If InCheckEvent Then Exit Sub InCheckEvent = True Check2Value = (Check2Value + 1) Mod 3 Check2.Value = Check2Value DoEvents InCheckEvent = False End Sub
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications