Get Value of dynamic created checkboxes

Hello there,

i've got the following problem to solve:
In my programm certain checkboxes are created dynamicly by the following code:
Sub CreateChkBoxes(ByVal Jahr As String)

Dim i As Integer
Dim chkbox As MSForms.CheckBox

For i = 0 To 5

Set chkbox = frmTest.Controls.Add("forms.checkbox.1")

With chkbox

.Caption = "test" & i
.Left = 276
.Top = 42 + 18 * i
.ForeColor = &H8000000E
.name = "chk" & .caption

End With

Next
End Sub

In the next step, I need to get the value of each of the checkboxes created. As I don't want to use the fix names of the boxes, I don't know how to access them dynamicly.

Thanks a lot

Finrod

Comments

  • : Hello there,
    :
    : i've got the following problem to solve:
    : In my programm certain checkboxes are created dynamicly by the following code:
    : Sub CreateChkBoxes(ByVal Jahr As String)
    :
    : Dim i As Integer
    : Dim chkbox As MSForms.CheckBox
    :
    : For i = 0 To 5
    :
    : Set chkbox = frmTest.Controls.Add("forms.checkbox.1")
    :
    : With chkbox
    :
    : .Caption = "test" & i
    : .Left = 276
    : .Top = 42 + 18 * i
    : .ForeColor = &H8000000E
    : .name = "chk" & .caption
    :
    : End With
    :
    : Next
    : End Sub
    :
    : In the next step, I need to get the value of each of the checkboxes created. As I don't want to use the fix names of the boxes, I don't know how to access them dynamicly.
    :
    : Thanks a lot
    :
    : Finrod
    :
    :
    It may be easier to have created a control array in the first place. Only one checkbox control needs to exist on the form initially. Then you could loop through the control array and check the value of each.

    The only other way would be to loop through all the controls on the form looking for checkbox controls each time one is found then check its value.

    Hope this helps a little.


    John ;-)
  • : : Hello there,
    : :
    : : i've got the following problem to solve:
    : : In my programm certain checkboxes are created dynamicly by the following code:
    : : Sub CreateChkBoxes(ByVal Jahr As String)
    : :
    : : Dim i As Integer
    : : Dim chkbox As MSForms.CheckBox
    : :
    : : For i = 0 To 5
    : :
    : : Set chkbox = frmTest.Controls.Add("forms.checkbox.1")
    : :
    : : With chkbox
    : :
    : : .Caption = "test" & i
    : : .Left = 276
    : : .Top = 42 + 18 * i
    : : .ForeColor = &H8000000E
    : : .name = "chk" & .caption
    : :
    : : End With
    : :
    : : Next
    : : End Sub
    : :
    : : In the next step, I need to get the value of each of the checkboxes created. As I don't want to use the fix names of the boxes, I don't know how to access them dynamicly.
    : :
    : : Thanks a lot
    : :
    : : Finrod
    : :
    : :
    : It may be easier to have created a control array in the first place. Only one checkbox control needs to exist on the form initially. Then you could loop through the control array and check the value of each.
    :
    : The only other way would be to loop through all the controls on the form looking for checkbox controls each time one is found then check its value.
    :
    : Hope this helps a little.
    :
    :
    : John ;-)
    :
    Hi John,

    thanks for your reply, my problem is, that I don't know how to get the value of the box in a loop

    Example:

    Dim test as Control
    Dim i as integer
    for i=0 to formTest.controls.count

    msgbox(here I want to get the value of the checkbox with the count i)

    next

    But maybe I'm just thinking the wrong way o.0

    Have fun

    Finrod


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories