Checkbox Event

  • Thread starter Thread starter BHatMJ
  • Start date Start date
B

BHatMJ

I have 10 checkboxes that perform similar functions with a minor variation.
I'd like to make one "click" event subroutine but change the action depending
on the name of the control that initiated the event. Inside the subroutine,
is there a way to determine which control was checked? Which one initiated
the event?
 
If you're using checkboxes from the forms toolbar, you can assign the same macro
to each of them.

Option Explicit
Sub OneProcedure()
dim myCBX as checkbox
set myCBX = activesheet.checkboxes(application.caller)
msgbox mycbx.name 'for instance
End Sub

If you're using checkboxes from the Control toolbox toolbar, you could use 10
different _click events that just call a common routine:

Option Explicit
Sub Checkbox1_Click()
call CommonProc(me.checkbox1)
end sub

Sub CommonProc(CBX as msforms.checkbox)
msgbox cbx.name
end sub
 
Exactly what I needed! Thanks.

Dave Peterson said:
If you're using checkboxes from the forms toolbar, you can assign the same macro
to each of them.

Option Explicit
Sub OneProcedure()
dim myCBX as checkbox
set myCBX = activesheet.checkboxes(application.caller)
msgbox mycbx.name 'for instance
End Sub

If you're using checkboxes from the Control toolbox toolbar, you could use 10
different _click events that just call a common routine:

Option Explicit
Sub Checkbox1_Click()
call CommonProc(me.checkbox1)
end sub

Sub CommonProc(CBX as msforms.checkbox)
msgbox cbx.name
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

Back
Top