Need help with adding Controls and event handlers at runtime

M

martin.zackrisson

I've gotten thus far that I've got a grid of 7x4 checkboxes and the
equal amount of labels that are being created while initiating my form.
Both resides in arrays. I've made a class module that is linked to the
checkboxes so that if one changes the value it triggers my
eventhandler. Now the problem is that while the excel runs the
eventhadler (one for all the checkboxes all togeather, which is sweet)
i can't as far as i can see access the individual checkboxes and labels
through their array reference

---
To explain it in terms of code I have an empty form that when initiaded
runs comands something like this
----

dim myChkBox (1 to 7, 1 to 4), myLabel(1 to 7, 1 to 4) as Control
dim i,j as integer
dim tempCB as clsCBEvents 'thats the name of my class module
dim CBcol as New Collection

for i = 1 to 7
for j = 1 to 4
Set myChkBox(i,j) = Frame1.Controls.Add("Forms.CheckBox.1",
"myCB" & i & j)
Set myChkBox(i,j) = Frame1.Controls.Add("Forms.Label.1", "myCB" &
i & j)
With myChkBox(i,j)
' First i set sizes and such (not included here)
set tempCB = new clsCVEvents
set tempCB.cb = myChkBox(i,j)
CBcol.add tempCB
next j
next i

----
now the class module named clsCVEvents
----

Public WithEvents cb As MSForms.CheckBox

Private Sub cb_Change()
'first i extract i and j from the last 2 positions through
activecontrol.name
'then i need to A) be able to change the properties of
myChkBox(i,j) and myLabel(i,j) oe
' B) be able to call a sub somewhere that might be able to
' or in any other way change the properties of those two
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top