Form Initialize Event

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
I just realized that when I load a UserForm and start setting the values of the controls that the code starts running the click events for those controls. If I use an initialize event (syntax?) will that eliminate the click events executing?

Thank you.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Not necessarily - events will fire because of actions you take in the initialize event too.
 
Upvote 0
Thank you. Is there an effective way to circumvent this without a lot of extraneous code?
 
Upvote 0
It depends. ;)

If something triggers an event, you should try to write the code so that there are no exceptions - that is, no cases where you sometimes want the event to fire and sometimes not. That is, let your events do the work and don't try to avoid them.

Worst case (I consider this poor design for user forms):
create a private variable called "SuppressEvents" or what have you. When you write your event code:

Code:
Sub Some_Event()
If Not SuppressEvents Then
    'Do event code
End If
End Sub

Then you can avoid the event with:

Code:
SuppressEvents = True
TriggerEvent()
SuppressEvents = False
 
Upvote 0
I think that answers my question. My main purpose isn't that the event is doing something unwanted, just unnecessary and ultimately inefficient. If I get to the point where the events are consuming too much time on loading the form then I might look to stop them.

Thanks for the help.
 
Upvote 0
I worked through a similar case once. In fact I did use the hack described above to shut off events for some combo boxes or list boxes that I was manipulating. ultimately weeded them out to the point where I could let the events fire and everything was triggered purely through the event code itself. I learned a lot about form events in the process - I think I even created a label on the form to list the events as they fired so I could understand what was happening when my form opened. But I believe I ended up with one listbox that I know was being loaded twice when the form opened - so I couldn't work it out to perfection {sigh}.
 
Upvote 0
I'm hoping to develop some of that efficiency with experience. Thanks again for the help.
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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