Last updated: 18 Jun 2003
The has been some disagreement on the list about this. Some people swear it works perfectly all the time, others seemingly have frequent problems. Whatever, here is a summary of what has been said:
Paul Bent writes:
Initialize should execute when the apr is opened. Say you want to call a
logon procedure, check the registry, call API functions to get system
parameters (eg short date format) initialize variables etc etc. Not much
use if this only happens when the user first clicks a button (say); they
could have been working in the apr for any length of time already.
It isn't a good idea to put Initialize code in DocumentOpened or
OpenWindow events or it will execute every time these events fire
instead of just once when the apr opens. To avoid this you need to hard
code the apr name in the event script which will cause it to fail if the
apr is renamed.
However, putting a single comment character in OpenWindow works around
the Initialize problem thank goodness!
Conversely, David Legge writes:
The initialize sub will only run when (just before) the first bit of code
gets invoked. I suppose there is no need to run it if no other code ever gets run!
If you want a code to run when a doc is opened, (the script equivalent of the Open macro) then place it in the openwindow event of the Documentwindow object in your file. (BTW If you have anything in Sub initialize it will also then run - because the Openwindow event is triggered)
The Sub Initialize is also run if you have edited code in the IDE (again only when the next piece of your code is invoked) So placing "documentopen" initialisation in Sub Initialize can confuse you when editing your code.
You will find Documentwindow is the last item in your list of views in the Object: list in the IDE. You have to expand yourfile object above the Approach objects to see it.
Unlike Paul, I think Initialize is now working correctly!