PDA

View Full Version : Solved: Single Event Handler for Multiple Checkboxes



bbk5
06-21-2007, 01:26 PM
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!

Bob Phillips
06-21-2007, 02:22 PM
Here is an example

bbk5
06-22-2007, 05:08 AM
Thanks so much, that is great!

Greenrent
10-02-2010, 01:27 AM
Nice post... interesting !

Paul_Hossler
10-02-2010, 08:16 AM
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

Bob Phillips
10-02-2010, 08:38 AM
It did Paul, but that was years ago and old attachments get stripped by the admins for some unfathomable reason.