Forms 'On Load' Property

  • Thread starter Thread starter Mike C.
  • Start date Start date
M

Mike C.

Hello.

I have a form, 'frmSecurityNameList', that when it is
opened runs a certain VBA script. This script, which is
pretty long, is located in the "On Load" property of the
form. Recently I have redesigned the database and now I
have made frmSecurityNameList a subform of frmMain with
its 'Visible' property set to 'No'. On the original
button that was used to open the form, it had the simple
code

DoCmd.OpenForm ("frmSecurityNameList")

Now I have it so when the button is clicked it makes
frmSecurityList visible with the code

frmSecurityNamelist.Visible = True

However, just making it visible means the the form is not
loading, thus the script does not run.

Where else can I place the script or is there another way
around this?

Hope this makes sence.

Any help would be appreciated.

MC
 
Even as a subform, the subform's On Load event will occur when the main form
is being loaded. In fact, if memory serves me correctly, the subform loads
before the main form. I've successfully used a subform's OnLoad event to run
code for the subform, and all I do is open the main form that contains the
subform. Are you sure the subform's OnLoad event isn't running when the main
form opens? Put your code back into the subform's OnLoad event and check.
 
Well, there are tons of paces you could put it, depending on when & how
often you want it to run. And you have not told us that, so it's hard to
suggest the right place!

Here are some choices:

- leave it where it is already: it will still run when the subform is loaded
initially, regardless of whether it is visible or not, afaik;

- in the Open or Load event of frmMain;

- in the button code which makes frmSecurityNameList visible;

- in your main menu or switchboard form;

- in your database startup form or module;

HTH,
TC
 
Back
Top