Keithyboy1


I have created a customised control in a class module, which works in a similar way to a combo box. It consists of a label, on which I have a button. When the button is clicked, a frame control appears below in a similar fashion to a combo drop down pane, on which I have various check boxes which a user can check or uncheck as required. The button click event basically sets the visible property of the frame to true or false accordingly.

My problem is, if the form on which my custom control resides has its ShowModal property set to false, the event handler for the button does not fire! I have checked this by placing a msgbox inside the event handler. When the form is set to modal, sure enough it fires and the msgbox appears.

Can anyone offer any insight into why this happens and how I can correct it.

Additional info that may assist anyone in diagnosing my probem:

I have created a class module to handle this custom control, within which I have declared various MSForms control variables, the command button controls being declared WithEvents.

I have a ParentForm property, which is set to a UserForm which already exists in the designer, once my class had been instantiated in a regular code module. Within the class, the controls are then set by adding them to the Controls collection of the ParentForm property (e.g. Set MyFrameVariable = ParentForm.Controls.Add("Forms.Frame.1"). I have set all my controls on the form in this way.

Events are then handled within the class, by virtue of declaring them WithEvents.

Like I say, the control works perfectly in a modal form, but set it to a non-modal form and the event don't fire!

Please help!

Many thanks!




Re: Problem with events

Keithyboy1


Anyone

Either this is an obscure bug of some kind, or I have done something obviously wrong. Either way, someone must have the expertise enough to tell me either way






Re: Problem with events

Andy Pope

Hi,

I don't think we have enough detail of your actual code to resolve the problem.

If you want to send your file to me I will have a look.

andy at andypope dot info





Re: Problem with events

Keithyboy1

Ok, I've sorted my own problem and it was a rather stupid beginner mistake to make for which I should have known better!

I had a sub routine in a regular code module, which declared and created an instance of my control class and ended by showing the form. The fact I declared my class variable within the routine was the mistake. The form itself, being modal by default, meant my class could persist in memory while the form was open, but as soon as I set it to non-modal of course, my class disappeared from memory once the routine had ended.

I've since declared my class variable at a module level and all is fine.

Many thanks for offering to help, Andy! I apologise for being blunt but I have been desparate to solve this problem for the last 2 days and all the while it was staring me in the face!