Consulting

Results 1 to 6 of 6

Thread: Solved: Single Event Handler for Multiple Checkboxes

  1. #1

    Solved: Single Event Handler for Multiple Checkboxes

    So, I have a form which has around 90 checkboxes. However, they all act very similar when they are checked, so I'd rather not write 90 separate event handlers for each check box.

    I did come across the following semi-solution to the problem, but unfortunately couldn't make total sense of it. I've included the explanation I found below:



    first you add a class module to you vba project and create a simple var

    dim mycheck as checkboxprivate sub mycheck_click() 'add all relevent code hereend sub

    then you create a global array of you new class in your document.

    then in your init event for your document
    you iterate through the checkboxs in your document and redim your new array then set the ubound to equal the current checkbox.

    when this is done - all of the checkbox's respond to the event coded in the class module with out the effort of defining actions for each event.



    If anyone could help me out with how to implement this, I would really appreciate it. I defined the class like instructed, and made a global array of the class in my form code as follows:

    Dim checkArray() As Class1

    Then, I try the following:

    For i = 1 To 90
    ReDim Preserve checkArray(0 To i)
    Set checkArray(i) = Me.Controls("CheckBox" & i)
    Next i


    However, this is not working due to type differences. I've been idling trying to fix this problem and was hoping someone could give me some insight. It would be a HUGE help to get this sorted out.

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is an example
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thanks so much, that is great!

  4. #4
    VBAX Newbie
    Joined
    Oct 2010
    Location
    Germany
    Posts
    2
    Location
    Nice post... interesting !

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Quote Originally Posted by xld
    Here is an example
    Sorry, but nothing came through with the post.

    Was there an attachemnt or link I missed?

    Paul

    Edit - My bad. I just noticed that the original post was in 2007, but the latest post was recent

    However, I'd still be interested in the example if it's available

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It did Paul, but that was years ago and old attachments get stripped by the admins for some unfathomable reason.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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