PC Review


Reply
Thread Tools Rate Thread

Dim ChkBoxes() As New Class1 Dilemma

 
 
PJ Murph
Guest
Posts: n/a
 
      3rd Apr 2009
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?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      3rd Apr 2009
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





PJ Murph wrote:
>
> 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?


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dim ChkBoxes() As New Class1 PJ Murph Microsoft Excel Programming 2 11th Apr 2009 03:29 PM
Set Class1Var = New Class1 Dave D-C Microsoft Excel Programming 6 15th Sep 2007 12:05 AM
WindowsXP and IE Dilemma Dilemma Dilemma, Please Help!! =?Utf-8?B?Qk9CMjI3?= Windows XP Configuration 0 4th Apr 2006 05:52 PM
exporting an Access report with chkboxes to word =?Utf-8?B?R2Vvcmdl?= Microsoft Access External Data 1 23rd Jun 2005 06:46 AM
This is how you set an SMS to CLASS1 =?Utf-8?B?VmlzaGFsIFJhc3RvZ2k=?= Microsoft Dot NET Compact Framework 0 22nd Jun 2004 01:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:09 PM.