Can events work with run-time-created Forms-controls?

PSC

New Member
Joined
Jul 16, 2006
Messages
15
Hi

I have a specific question about getting events to work with run-time created controls of VBA forms version 2.01

I've made a VBA form that has 2 static command buttons (OK and Cancel). The init-sub of the form creates x option buttons at run-time. The content of the option buttons are fecthed from an Excel Range.

What I now do is to scan through the Controls("name of the control") in a loop to figure out which option button is currently active when the user click on the OK-button.

It all works well, but I want to enable *_DblClick() event for all the option buttons so it is possible to make a choice by double-clicking on any of the option button.

If I create event-subs myself identical to what they would get at creating them at design, they will not trigger.

Does anyone know how the fetch double-click event on controls created by code at run-time? If you do, please, let me know.
 
Thank you Tom

The code works like a charm.

The only modification required to get it to work in VBA 5 was to define the Subs as Public instead of Friend.

I was wondering before why I could define Subs as Public in a code of a form but was unable to call them from a module. Now, I know.

It seems like I haven't gone my last "class" after all. :wink:
Now I know that "classes" are good for something.

Thanks again, and if you have any succestion of a good VBA book that you've read yourself, please, let me know.
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
See my previous post. It think you may have missed it. I mentioned a book there.
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,634
Members
449,460
Latest member
jgharbawi

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