Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamic checkbox events

1 view
Skip to first unread message

stefan brunzell

unread,
Oct 3, 2001, 10:20:41 AM10/3/01
to
Hi there,

I have create some checkboxes as the code below.
That's works fine but, how should I know if there is an click event on any
of the checkboxes?

For i = 1 To any_number
Set checkbox(i) =
multipage.Pages(1).Controls.Add("forms.checkbox.1", "checkbox" & (i),
Visible)
checkbox(i).Left = 5
checkbox(i).Top = i * 16 + 4
checkbox(i).Width = 161
next i


Thanks in advance
Stefan

pds

unread,
Oct 3, 2001, 6:02:14 PM10/3/01
to
"stefan brunzell" <s.bru...@telia.com> wrote in message news:<Z8Fu7.3347$XO2.4...@newsb.telia.net>...

Stefan,

You may be able to use the old style forms checkbxes (ie. available
from the forms toolbar) to do this.

With these controls you can use the OnAction property to assign a
macro to assign to the event.

ActiveSheet.CheckBoxes.Add(432, 25.5, 96, 17.25).Select
Selection.OnAction = "CheckBoxClick"

The CheckBoxClick macro could then perform the required task.

Hope this helps,

Graham

--------------
Progressive Data Solutions
http://www.pdsolutions.com.au
Home of VB Code Cutter - VB/VBA Code Library & Dev Tool with Free code
formatting/indenting

Francisco Mendez

unread,
Oct 3, 2001, 6:38:59 PM10/3/01
to
Hi Stefan:

Ii the checkboxes are in a userform write an "On_Click" sub, i. e., in
design mode right click your checkbox, select view code from the context
menu, or if the check box is embedded in a page write the "On_Click" sub in
the class module for that page. And so on for all the check boxes in your
user form or page.

Hope it works. Regards,

FM.
...


stefan brunzell

unread,
Oct 4, 2001, 4:14:02 AM10/4/01
to
Hi graham,

My checkboxes are on userforms and I the number of checkboxes can vary from
time to time.
So, for that reason I can't program a sub for each checkbox that can occur.

Thank's anyway
/Stefan

pds <in...@pdsolutions.com.au> skrev i
diskussionsgruppsmeddelandet:3d1eb4db.01100...@posting.google.com
...

stefan brunzell

unread,
Oct 4, 2001, 4:16:35 AM10/4/01
to
Hi FM,

Thanks for the answer, but this is the problem.
I don't have any checkboxes in designmode. I create them i run-time.

Regards Stefan


Francisco Mendez <ifr...@prodigy.net.mx> skrev i
diskussionsgruppsmeddelandet:egfFExFTBHA.2024@tkmsftngp07...

pds

unread,
Oct 4, 2001, 6:23:17 PM10/4/01
to
Stefan,

I had another look at this problem and this is what I found...
It might be of some use to you.

What you need to do is:

1. Create a new workbook.

2. Add a new user form with this code behind it.

Option Explicit

Private moCol_EventHandlers As Collection

Private Sub UserForm_Activate()

Dim i As Integer
Dim lTop As Long

Dim oCtrl As Control
Dim oChkBox_EventHandler As CCheckBox

Set moCol_EventHandlers = New Collection

For i = 1 To 5
Set oCtrl = Controls.Add("Forms.CheckBox.1", "chk" & CStr(i),
True)
Set oChkBox_EventHandler = New CCheckBox
Set oChkBox_EventHandler.SetCheckBox = oCtrl
oCtrl.Caption = "Checkbox" & CStr(i)
oCtrl.Top = lTop
moCol_EventHandlers.Add oChkBox_EventHandler, oCtrl.Name
lTop = lTop + 20
Next i

End Sub


3. Add a new class module named CChkBox with this code:

Option Explicit

Private WithEvents moChkBox As msforms.CheckBox

Public Property Set SetCheckBox(ChkBox As msforms.CheckBox)
Set moChkBox = ChkBox
End Property

Private Sub moChkBox_Click()
Select Case moChkBox.Name
Case "chk1"
MsgBox "1"
Case "chk2"
MsgBox "2"
Case Else
MsgBox ">2"
End Select
End Sub

This may not be exactly what you want but you may be able to work with
it from here.

Hope this helps.

Regards

stefan brunzell

unread,
Oct 5, 2001, 9:52:29 AM10/5/01
to
Graham,
Thank's again.
I have solved the problem now and the solution is nearly the same as yours.
I use classmodules and in there I can use WithEvents to track any events...
regards Stefan

0 new messages