?
Solved

Using OnOpen vs. OnLoad

Posted on 2010-09-01
3
Medium Priority
?
849 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

840 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