(Re)assigning On Click event of a control

HansVanSteen

New Member
Joined
Jun 20, 2012
Messages
3
(each time the text says "On Click", one has to read this as one word without the space. That word is censored :eeek:. I suppos to avoid scripting )

In a userform I use radio buttons (a frame holding option buttons, only one is depressed) and don't want to scan all objects to check the status. My idea is to have a generic event procedure to catch all On click events and set the "tag" property of the frame. I tried something like the code below.(Userform_initialise)

Normally in delphi I would call the inherited On Click and assign an OVERRULE procedure to do this but being a newbee to VB I have not the foggiest idea how to do this.


Private Function OptionButtonOn ClickEvent(ctrl As Control)
ctrl.Parent.Tag = ctrl.Caption
End Function

Sub Userform_Initialise()
Dim ctrl As Control

For Each ctrl In MainForm.Controls
If InStr(Ctrl.name, "Option") <> 0 Then
Rem Set ctrl!on Click = OptionButtonOn ClickEvent(ctrl)
End If
Next ctrl
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
You can't really do this easily in VBA, it's not designed that way.

Your options are either to loop through the form controls to check their status, or create an events class to handle the click event of a particular control, you then store these in a collection. This does seem a bit overkill for checking the value of option buttons though
 
Upvote 0
You can't really do this easily in VBA, it's not designed that way.

Your options are either to loop through the form controls to check their status, or create an events class to handle the click event of a particular control, you then store these in a collection. This does seem a bit overkill for checking the value of option buttons though

Thanks, I don't mind coding some overkill if needed. I thought VBA was an extension of VB. Or is object programming and inheritance not part of
VB(A)? Anyway, I now know what to do. Just scan the lot. What do you think, shall the ctrl.parent.tag = ctrl.caption work?

greets...

Hans
 
Upvote 0
Not really, it's a stripped down version of VB6 so doesn't support full inheritance, only interface inheritance.

I don't know because I don't know what you're wanting to do with the data once you've got it. I would have thought a class level variable would be better suited?
 
Upvote 0
I thought to scan trough all objects and set the tag property of the parent, than scan objects again for frames and color the frames parent green to indicate that all radio groups have been touched. Then finally scan the objects again for the page objects and readout the colors et voila, there's your result. It's not like you will win a programming contest with this code but then again, this isn't real programming, is it?
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top