+ Reply to Thread
Results 1 to 8 of 8

Checkbox dynamically created

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel 2010
    Posts
    28

    Checkbox dynamically created

    I have the following code that allow me to have dynamic checkboxes in an userform.

    Private Sub UserForm_Activate()
        Dim theCheckBox_ID(1 To 10) As MSForms.CheckBox
        Dim CheckBoxTop As Integer
        CheckBoxTop = 75
        Dim i As Integer
        For i = 1 To 10
            Set theCheckBox_ID(i) = Controls.Add("Forms.CheckBox.1")
            With theCheckBox_ID(i)
                .Name = "chk_" & i
                .Value = False
                .Caption = ""
                .Top = CheckBoxTop
                .Left = 12
            End With
            CheckBoxTop = CheckBoxTop + 30
        Next
        Me.Height = CheckBoxTop + 100
    End Sub
    In such UserForm I have also a ComandButton; I would like to have specific MsgBoxes for each selected Checkboxes when I click on it.

    The following code doesn't work as expected.

    Private Sub cmd_SAVE_Click()
        Dim j As Integer
        For j = 1 To 10
            If theCheckBox_ID(i).Value = True Then
                MsgBox (theCheckBox_ID(i).Name)
            End If
        Next
    End Sub
    What's wrong???

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Checkbox dynamically created

    Hi Vale1976
    try so
    Private Sub cmd_SAVE_Click()
    Dim j As Integer
    For j = 1 To 10
        If Me("chk_" & j).Value Then MsgBox Me("chk_" & j).Name
    Next
    End Sub

  3. #3
    Registered User
    Join Date
    06-12-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Checkbox dynamically created

    I tried so, but the following error is displayed:

    Run-time error '-2147024809 (80070057)':
    Could not find the specific object.


    Any other suggestion???

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Checkbox dynamically created

    I do not believe
    see attachment
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-12-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Checkbox dynamically created

    Just another question.

    How can I define what happen when I click on a dynamic checkbox?

    I think this code is not right Private Sub Me("chk_" & i)_Click()

  6. #6
    Registered User
    Join Date
    06-12-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Checkbox dynamically created

    FANTASTIC!!!!!!! Thanks a lot

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Checkbox dynamically created

    maybe so
    see attachment
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-12-2013
    Location
    Rome, Italy
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Checkbox dynamically created

    Thanks a lot again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1