Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2007, 06:30 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with events not firing

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, onto which I have a command button (or drop button in this case). When this button is clicked, a frame control appears below in a similar fashion to a combo drop down pane. This frame contains various check boxes which a user can check or uncheck as required and then click an OK button, also in the frame. The drop 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 drop 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. The form I have designed it for is not a modal form, so as it stands, the control won't work.

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 in my class, which is set to a UserForm already existing 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!


 
Old June 16th, 2007, 05:47 AM
Authorized User
 
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.



 
Old August 3rd, 2016, 05:39 PM
Registered User
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default thanks

Thank you for posting this.

I was trying to do the same thing and I had the exact same problem.
Turns out I did the same error and my event handling class was just silently vanishing at the end of my subroutine.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Events are not firing msrnivas .NET Web Services 14 April 21st, 2008 06:37 AM
Events not firing in IE malk ASP.NET 1.0 and 1.1 Professional 7 August 29th, 2006 01:32 PM
Windows control events not firing bmains C# 2005 2 June 5th, 2006 09:11 PM
Events firing for control in one instance, but... thanie2001 ASP.NET 1.0 and 1.1 Professional 3 January 23rd, 2004 03:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.