View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Urgent help needed - Change in userform...

Hi barkiny,

Search this ng for "WithEvents Checkbox", here's one pasted below -

" start copied post
Insert a class module named "Class1" and two command buttons near the bottom
of a userform.

'' start code in Class1
Public WithEvents cbx As MSForms.CheckBox

Private Sub cbx_Change()
MsgBox cbx.Tag & " : " & cbx.Value, , cbx.Name
'do stuff
End Sub

'' end code in Class1

''Start code in Userform1
Dim colClsChBoxes As New Collection

Private Sub CommandButton1_Click()
Dim cls As Class1
Dim cb As Control
For i = 1 To 3
Set cb = Me.Controls.Add("Forms.CheckBox.1", "My Check Box " & i, True)
With cb
..Left = 10
..Top = (i - 1) * 30 + 5
..Width = 90
..Height = 30
..Caption = .Name
End With
Set cls = New Class1
Set cls.cbx = cb


colClsChBoxes.Add cls
cb.Tag = colClsChBoxes.Count
Next


End Sub


Private Sub CommandButton2_Click()
Dim cnt As Long
Dim arr() As Boolean
cnt = colClsChBoxes.Count
If cnt Then
ReDim arr(1 To cnt)
For i = 1 To cnt
arr(i) = colClsChBoxes(i).cbx.Value
MsgBox arr(i), , colClsChBoxes(i).cbx.Name
Next
Else
MsgBox "No checkboxes in collection"
End If
End Sub


'' end code in Userform1

Class's for existing checkboxes could have course been instanciated and
added to the collection in the Intitialize event.

If you want to refer to the collection of class's (and hence checkboxes)
elsewhere in your project, declare colClsChBoxes as Public in a normal
module.
" end copied post

Now add a wide textbox named TexBox1, comment the msgbox line and replace
with

Dim s As String
s = cbx.Name & " Tag: " & cbx.Tag & " checked: " & cbx.Value
cbx.Parent.TextBox1.Text = s

Regards,
Peter T


"barkiny" wrote in
message ...

thanks for your reply herald
As i said there are too many boxes, I dont want to call one by one


--
barkiny
------------------------------------------------------------------------
barkiny's Profile:

http://www.excelforum.com/member.php...o&userid=20397
View this thread: http://www.excelforum.com/showthread...hreadid=566387