[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using OnOpen vs. OnLoad

Posted on 2010-09-01
3
Medium Priority
?
839 Views
Last Modified: 2012-05-10
In my Access 2007 database, I have several forms and each form has several subforms. I have a lot of VBA code in the OnLoad event of most of the forms/subforms to initialize controls, turn controls visible/not visible under certain conditions, etc.. I also consistently close a form before opening a new one.  I have 2 questions:

1) What is the difference between using OnOpen and OnLoad events in the forms/subforms? Can either be used to initialize controls and set controls visible/not visible or is OnLoad preferred?
2) Is it preferred to close a form before opening a new one if the user is going back and forth between 8-10 different forms?
0
Comment
Question by:newbie46
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 1000 total points
ID: 33583373
great explanation of the 2 here:
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_22552691.html

If a form will be reused multiple times, I normally hide / unhide them instead of opening and closing.
0
 
LVL 10

Assisted Solution

by:t_hungate
t_hungate earned 1000 total points
ID: 33583428
The main difference is when the event are triggered.  For instance you can exit a procedure at OnOpen, because the form is not yet "Open", however you can not cancel an OnLoad, as the form will have been opened and the user will see it, and the error.  

These sites, break it down a little different, but I think that they are good sources.

http://office.microsoft.com/en-ca/access-help/order-of-events-for-database-objects-HP005186761.aspx?redir=0
http://www.accessmonster.com/Uwe/Forum.aspx/access-forms/42103/On-load-vs-On-open
http://database.itags.org/ms-access-database/58505/

Bottom line, is look at the order of events and figure out where the most appropriate place is to trigger your code execution.

Hope this helps.


TLH
0
 
LVL 58
ID: 33585314
Only other thing I would add that I didn't see in those links is that in the OnOpen event, the form is still being initialized, so controls may or may not exist at that point.  You can't count on a control being there until the OnLoad event.
If you need access to a control in the OnOpen event (because you might wish to cancel), you can do a Me.Repaint to force all the controls to be created.
One other important gotcha with subforms; their events occur before the main forms. So when you've reached the main forms OnLoad event, all the other events have already occured for the subforms (Open, Load, Current).
JimD.

0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question