VB6 Checkbox fill all to true

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • esgilmore
    New Member
    • Oct 2008
    • 3

    #1

    VB6 Checkbox fill all to true

    I am working on a project for work and have been able to find most of my answers. This one still causes me issues. I am sure whatever it is Im doing wrong, it's simple.

    I created a userform in VB6, placed Frame1 on it and then added 26 checkboxes (each one has its own code and is working) and 3 commandbuttons (ok, cancel, check all) on the frame. Everything is working the way i need it except the check all button. I have tried doing this several ways and just can't get anything to work.

    After the command button "OK" is pressed it will run the code for each check box that = true. I also have a cancel command button that works.

    I am trying to add a commandbutton/checkbox (have tried both) that will check but have been unsuccessful with either button or calls. I could do it the long way by setting each checkbox# = true, but never imagined this would take so long.


    Current code (x is always false??):
    Code:
    Private Sub CommandButton3_Click ()
    Dim x as Control
    
    For each x in Userform1.Frame1.Controls
       If TypeOf x is CheckBox then
        x.value = true 
       End if
    Next
    End Sub
    Any help is appreciated.
    Scott
  • gwbob
    New Member
    • Oct 2008
    • 14

    #2
    try putting the code in the select all button to set the value on each check box to true so that they are all checked i think that might work

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      I am not sure as I use .net but but should that not be ' x.checked = true ' and not x.value ?

      Comment

      • esgilmore
        New Member
        • Oct 2008
        • 3

        #4
        Originally posted by jg007
        I am not sure as I use .net but but should that not be ' x.checked = true ' and not x.value ?
        The For loop runs itself 29 times (so that tells me it is running through each of the buttons/checkboxes). However Typeof X is never = to a checkbox so it doesn't get past that line to then goto the next line to change it. the X value must be passing something just not the correct way. Once I get that I will keep this in mind that I may have to change that piece to get it to actually change.


        Thank you
        Last edited by esgilmore; Oct 3 '08, 04:31 PM. Reason: More Clarification

        Comment

        • esgilmore
          New Member
          • Oct 2008
          • 3

          #5
          Originally posted by gwbob
          try putting the code in the select all button to set the value on each check box to true so that they are all checked i think that might work

          I think I understand what you mean. Which is what I did to get this pushed out to the user (since they don't see the code and only know if the checkboxes get checked or not)

          Code:
          Commandbutton3_Click()
           
          Checkbox1.Value = True
          Checkbox2.Value = True...etc.
          But everytime I add a new button with code I have to go back into the Commandbutton3 and add the new check box. this just makes it cumbersum instead of using some sort of For Loop.

          Thanks

          thanks

          Comment

          • lee123
            Contributor
            • Feb 2007
            • 556

            #6
            hello after reading your post i have done something i didn't see in your code and it works for me so if i was you i would try it:

            Code:
            Private Sub cmdOK_Click()
            If cmdOK Then
                Check1.Value = 1
                Check2.Value = 1
                Check3.Value = 1
                Check4.Value = 1
            End If
            End Sub
            as you can see this example will work you can put the rest of checkboxes in.

            lee123

            Comment

            Working...