Dim ChkBoxes() As New Class1 Dilemma

P

PJ Murph

I have the following code in a module (Module1):
Option Explicit
Dim ChkBoxes() As New Class1
Sub Auto_Open()

Dim CBXCount As Long
Dim OLEObj As OLEObject
CBXCount = 0

For Each OLEObj In Worksheets("DAL").OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
CBXCount = CBXCount + 1
ReDim Preserve ChkBoxes(1 To CBXCount)
Set ChkBoxes(CBXCount).CBXGroup = OLEObj.Object
End If
Next OLEObj

End Sub

I have the following code in a Class Module (Class1):
Public WithEvents CBXGroup As MSForms.CheckBox
Private Sub CBXGroup_Change()
Dim WhichCheck As Long
WhichCheck = Mid(CBXGroup.Name, Len("cbxCheck") + 1)
With CBXGroup.Parent.OLEObjects("tbxCheck" & WhichCheck)
.Visible = CBXGroup.Value
.PrintObject = CBXGroup.Value
End With

End Sub

This works perfectly for the checks presented portion of my form. The
problem is that I have 3 different checkboxes; cbxCheck, cbxFee, and cbxHeld.
How do I code to track and differentiate all 3?
 
D

Dave Peterson

I'm kind of confused about what your question is.

The code was written to take advantage of a standard naming convention.

It looks like you should have checkboxes and textboxes named:
cbxCheck1 and tbxCheck1
cbxCheck2 and tbxCheck2
cbxCheck3 and tbxCheck3
and so forth

If you're saying that you have 3 additional checkboxes that you want to process,
you could use something like:

Public WithEvents CBXGroup As MSForms.CheckBox
Private Sub CBXGroup_Change()
Dim WhichCheck As Long

select case lcase(cbxgroup.name)
case is = lcase("cbxFee")
'do the work for the Fee
case is = lcase("cbxheld")
'do the work for Held
case else 'everything else would be named like cbxcheck#, right?
WhichCheck = Mid(CBXGroup.Name, Len("cbxCheck") + 1)
With CBXGroup.Parent.OLEObjects("tbxCheck" & WhichCheck)
.Visible = CBXGroup.Value
.PrintObject = CBXGroup.Value
End With
end select

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