Solved

Using OnOpen vs. OnLoad

Posted on 2010-09-01
3
757 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
3 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 250 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 250 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 57
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now