Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default UserForm_Initialize

Yes, I considered that, but this form doesn't normally get closed in that
particular
Excel session, but instead gets minimized via the normal Windows minimize
controls added via the API. So, I don't hide the form, but either it gets
minimized
by the user or gets unloaded fully.
Doing Load UserForm doesn't take long, so it would be no problem to do this
again, rather than UserForm.Show of a hidden form.
The only thing I do in the activate event is set the position of the form on
the screen.

RBS



"Edwin Tam" wrote in message
...
Have you considered "UserForm_Activate" instead? That could be much easier
to
control.

Normally, before showing a form, if you want to ensure the
UserForm_Initialize is fired, there are two main things you can choose to
do:
1) before showing the form, you unload it. This ensures the form is
unloaded. For example:

On error resume next
unload userform1
on error goto 0
load userform1
userform1.show

2) At the end of your macro, unload all forms. For example:

On error resume next
unload userform1
on error goto 0


"UserForm_Initialize" does have its importance. It is normally used for
preparing your userform for being used. These may include:
1) adding items to listboxes and comboboxes,
2) setting the visibility of controls, etc.

Such tasks could be less efficient to be put into "UserForm_Activate".
Imagine, if you got a form which will be show/hide/show several times
during
operaion (e.g. a wizard), and you got a dropdown list of 12 months (Jan,
Feb
... Dec) and then a dropdown list containing years from 1980 to 2050. If
you
put the additem statements into "UserForm_Activate", the dropdown lists
will
be cleared and population every time the form is shown. But this is in
fact
unnecessary. Why doing it many times? Why not just once?

In the example, if you put the additem code into "UserForm_Initialize",
they
will be executed only once. Then you can use "UserForm_Activate" to set
the
listindex of those dropdown lists before the form is actually displayed.

Regards,
Edwin Tam

http://www.vonixx.com




"RB Smissaert" wrote:

No particular question really, but just an observation and maybe somebody
has some opinion about this.
When you have a complex VBA project with userforms it can be difficult to
control when the UserForm_Initialize
event will be triggered. I have found now that it is just much easier not
to
use this at all and make a procedure
that runs all the code that normally would go into UserForm_Initialize.
Then you can run this procedure whenever you want, for example after Load
UserForm.
Doing this gives you me more control and avoids problems.

RBS



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UserForm_Initialize Bob Phillips[_6_] Excel Programming 1 April 13th 06 04:43 PM
UserForm_Initialize error Jennifer Excel Programming 3 April 24th 05 09:58 PM
UserForm_Initialize() Joe Derr[_2_] Excel Programming 3 December 4th 04 04:23 AM
UserForm_Initialize Rob Excel Programming 2 January 15th 04 02:00 PM
UserForm_Initialize? How to update. Jelso Excel Programming 2 September 5th 03 07:51 AM


All times are GMT +1. The time now is 04:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"