none
Update many checkboxes RRS feed

  • Question

  • Hi Guys,

     

    I need some help in developing my code.  O have about 50 checkboxes and I want to be able to change the caption and colour when selected.  I want to be able to utilise a function that does this.  I have produced the code for this and works really well for just one checkbox.  Here is the code for the function that I have developed:

    Function update(whichone as single) ' whichone is the number of the checkbox to update

    If Me.CheckBox2 = -1 Then
      
        CheckBox1.Caption = "Selected"
        CheckBox1.BackColor = &H8000&
       
    ElseIf Me.CheckBox2 = 0 Then
        CheckBox1.Caption = "Not Required"
        CheckBox1.BackColor = &HFFFFFF
    End If

    My delemma is that I want ot be able to use this code when any of the 50 Checkboxes are selected rather than have this code inserted into every check box on Click.

    I wanted to have a "Call" to the function for all 50 checkboxes, something like this, but I just can't seem to quite work it out how do to this?

    Private Sub CheckBox2_Click() ' what needs to be in here to make my code work??
    dim selectedbox as single

    selectedbox = ?

    Call update(selectedbox)

    End Sub 

    Can anybody help me please?

    Thank ing you in advance!!

    Cheers,

    Don't know

    Thursday, October 20, 2011 9:41 PM

Answers

  • Hi Cindy,

    Yes I am definitely uding Microsoft Word 2003 version.

     

    I am using the checkboxes on a document ie. not on a userform.

     

    The checkbpoxes are used via:

    a. Entering Design mode on the Control Toolbox Toolbar

    b. Leave yuour mouse on the table where you want the checkbox to appear

    c.  Selecting the checkbox from the toolbar

    d.  The checkbox appears on the table

    e.  Populate every row of the table with checkboxes

    f. Reselect the design mode to enable the form again

    g. I have a table with about 50 rows

    h. The user selects which rows are appropriate for the ptoject that he wants to select.

    i  When the checkbox is selected I want the caption to change to "selected" from "not required"

    j. The colour is to change from white to green when selected as well

    g. 

     

    As I have so many chackboxes I wanted to have a function rather than coding every checkbox with this code:

     

    If Me.CheckBox1= -1 Then

    CheckBox1.Caption = "Selected"
    CheckBox1.BackColor = &H8000&

    ElseIf Me.CheckBox1= 0 Then
    CheckBox1.Caption = "Not Required"
    CheckBox1.BackColor = &HFFFFFF
    End If

     

    I hope this helps,

    Thanks very much again for answering, I do appreciate your input

    Cheers,

    Don't Know

     

    Friday, October 21, 2011 10:11 PM
  • Private Sub CheckBox1_Click()
        Update CheckBox1
    End Sub

    Private Sub CheckBox2_Click()
        Update CheckBox2
    End Sub

    Private Sub CheckBox3_Click()
        Update CheckBox3
    End Sub

    ' ... for as many checkboxes as there are in the document

    Sub Update(cb As Object)
        With cb
            If .Value = False Then
                .Caption = "Not Required"
                .BackColor = &HFFFFFF
            Else
                .Caption = "Selected"
                .BackColor = &H8000&
            End If
        End With
    End Sub

    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    Sunday, October 23, 2011 12:50 AM

All replies

  • You've posted this in a Word forum, but it's not clear whether you're using Word?

    If you are, are these checkboxes on the document, or in a UserForm?

    If on a document, what kind of checkboxes are they? If you're not sure, please list the command steps you follow to insert them?

    Finally, which version of Word is this?


    Cindy Meister, VSTO/Word MVP
    Friday, October 21, 2011 9:01 AM
    Moderator
  • Hi Cindy,

    Yes I am definitely uding Microsoft Word 2003 version.

     

    I am using the checkboxes on a document ie. not on a userform.

     

    The checkbpoxes are used via:

    a. Entering Design mode on the Control Toolbox Toolbar

    b. Leave yuour mouse on the table where you want the checkbox to appear

    c.  Selecting the checkbox from the toolbar

    d.  The checkbox appears on the table

    e.  Populate every row of the table with checkboxes

    f. Reselect the design mode to enable the form again

    g. I have a table with about 50 rows

    h. The user selects which rows are appropriate for the ptoject that he wants to select.

    i  When the checkbox is selected I want the caption to change to "selected" from "not required"

    j. The colour is to change from white to green when selected as well

    g. 

     

    As I have so many chackboxes I wanted to have a function rather than coding every checkbox with this code:

     

    If Me.CheckBox1= -1 Then

    CheckBox1.Caption = "Selected"
    CheckBox1.BackColor = &H8000&

    ElseIf Me.CheckBox1= 0 Then
    CheckBox1.Caption = "Not Required"
    CheckBox1.BackColor = &HFFFFFF
    End If

     

    I hope this helps,

    Thanks very much again for answering, I do appreciate your input

    Cheers,

    Don't Know

     

    Friday, October 21, 2011 10:11 PM
  • Private Sub CheckBox1_Click()
        Update CheckBox1
    End Sub

    Private Sub CheckBox2_Click()
        Update CheckBox2
    End Sub

    Private Sub CheckBox3_Click()
        Update CheckBox3
    End Sub

    ' ... for as many checkboxes as there are in the document

    Sub Update(cb As Object)
        With cb
            If .Value = False Then
                .Caption = "Not Required"
                .BackColor = &HFFFFFF
            Else
                .Caption = "Selected"
                .BackColor = &H8000&
            End If
        End With
    End Sub

    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org
    Sunday, October 23, 2011 12:50 AM
  • Hi Jay,

    Many thanks Jay thats exactly what I wanted to know!!

     

    Have a great Day!!

     

    Cheers,

     

    ian

     

     

    Sunday, October 23, 2011 2:37 AM