ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Userform runs other subs when initialized (https://www.excelbanter.com/excel-programming/322176-userform-runs-other-subs-when-initialized.html)

zipdog

Userform runs other subs when initialized
 
In trying to solve a problem with a user form, I began to suspect that
multiple subs were being triggered as soon as I showed the form. I put
a MsgBox into each sub in the code section of my userform, except for
Userform_Initialize. The form has two multicolumn list boxes, two combo
boxes, and three command buttons. Both listboxes and one combobox have
change event subs. When I initially call up this userform (from a
button in a Worksheet) the message box in the combobox change event sub
appears once, the message box in one listbox appears twice, and the
other appears three times! Is this normal behavior? Could this be why
my listbox selection values are being cleared unexpectedly?
I would really appreciate any help on this matter.


Tom Ogilvy

Userform runs other subs when initialized
 
Try using the click event rather than the change event.

--
Regards,
Tom Ogilvy


"zipdog" wrote in message
oups.com...
In trying to solve a problem with a user form, I began to suspect that
multiple subs were being triggered as soon as I showed the form. I put
a MsgBox into each sub in the code section of my userform, except for
Userform_Initialize. The form has two multicolumn list boxes, two combo
boxes, and three command buttons. Both listboxes and one combobox have
change event subs. When I initially call up this userform (from a
button in a Worksheet) the message box in the combobox change event sub
appears once, the message box in one listbox appears twice, and the
other appears three times! Is this normal behavior? Could this be why
my listbox selection values are being cleared unexpectedly?
I would really appreciate any help on this matter.




zipdog

Userform runs other subs when initialized
 
Thanks very much for responding. I have actually used both click and
change. Same effect. I have overcome the initial problem using an
event suppression solution from Dick Kusleika. Thanks, Dick! I also
changed the first procedure from initialize to activate, though I am
unclear what the difference is.

It still seems weird to me that change and especially click events fire
during Initialization. Even though I am please that I got my program
to work, I would still love to understand what's going on with
initialize, activate, and how they affect the values in listbox
controls.


Tom Ogilvy

Userform runs other subs when initialized
 
It depends on what you are doing in the Initialize and Activate events.

Using a boolean public variable is useful in many cases (but not all) to
block events from running.

--
Regards,
Tom Ogilvy


"zipdog" wrote in message
ups.com...
Thanks very much for responding. I have actually used both click and
change. Same effect. I have overcome the initial problem using an
event suppression solution from Dick Kusleika. Thanks, Dick! I also
changed the first procedure from initialize to activate, though I am
unclear what the difference is.

It still seems weird to me that change and especially click events fire
during Initialization. Even though I am please that I got my program
to work, I would still love to understand what's going on with
initialize, activate, and how they affect the values in listbox
controls.





All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com