Results 1 to 15 of 15
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Triple State Checkbox (VB6)

    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?

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    In VBA you set the set the TripleState property to true, and whilst I do not have VB6 available to me just know, I woul de surprised it was any different.

    Try CheckBox1.TripleState = True, in your FormLoad event.

    Andrew C

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: 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:
    <pre>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</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Triple State Checkbox (VB6)

    Sam,
    I recall reading somewhere (no idea where though!) that checkboxes in VB could have values of 0 (unchecked), 1 (checked) or 2 (dimmed). Is my memory failing me? (I hope not - I'm too young for that to be kicking in already! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Triple State Checkbox (VB6)

    <img src=/S/hairy.gif border=0 alt=hairy width=15 height=15> 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?
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Triple State Checkbox (VB6)

    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!
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    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

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Triple State Checkbox (VB6)

    But you could easily use the click event to cycle thru the three states, just make sure you use a global varable to "disable" the click event when you click it in code like I did in the example above.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Triple State Checkbox (VB6)

    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?
    Charlotte

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    Yes, VB checkboxes can have three states.
    Look at the Value property.

  11. #11
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    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

  12. #12
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Triple State Checkbox (VB6)

    But if you don't set a default stste for the control or you set the default to Null, wouldn't that serve the same purpose without requiring any "cycling"? You wouldn't ordinarily include a criteria condition in a query for a field where you wanted all records, regardless of value.
    Charlotte

  13. #13
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    I am creating an 'advanced search criteria' form and I would like users to be able to cycle through the three states on one of the check boxes.

  14. #14
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Triple State Checkbox (VB6)

    Here is the click event that you need to cycle:
    <pre>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</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  15. #15
    Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Triple State Checkbox (VB6)

    I came up with this:

    '//cycle through True, False & vbGrayed
    If chkIncDel(Index) = vbTrue Then
    i = i + 1
    Else
    If chkIncDel(Index) = vbFalse Then
    i = i + 1
    End If
    End If

    If i = 2 Then
    chkIncDel(Index) = vbGrayed
    i = 0
    End If

    i is an integer set to 0 on form load.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •