My dynamic CheckBox cann't work with class module! Anyone can help me? Thank you~

  • Hi guys, I Really need your help......


    I am new to VBA and I encountered a problem like this:

    I use class module to add 20 CheckBoxes dynamically on a form but when I click the CheckBox,it doesn't work!

    It seems that the CheckBox is not associated with class module.

    The form code is as below :
    Note1: The name of the form is " myForm" .

    Note2: The name of the frame on myForm is " myFrame".



    AND I use a class module (named "Class1") as below:

    Code
    Public WithEvents my_CheckBox As msforms.CheckBox
    
    Private Sub my_CheckBox_Click()
      MsgBox "Hello"
    End Sub

    Seeking your help. Please advise. Thanks in advance.

  • The declaration of the array needs to be outside any routines, so this line:


    Code
    Dim CheckBox_Voc() As New Class1


    needs to be at the top of the Userform code module.

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Code
    Thank you for your reply , you mean that I should change as below?
    
    Option Explicit
    Dim CheckBox_Voc() As New Class1 
    Private Sub UserForm_Initialize()
    .........
    end Sub

    I change it,but then another problem occurred.

    I have a sub in normal module,the sub like below


    Sub read_word()

    myForm.show

    End Sub


    I call the sub,then a message appeard:"Can't find Object" ← it means myForm

  • Glad to help. :)

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!