Solved

Using OnOpen vs. OnLoad

Posted on 2010-09-01
3
772 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

895 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

14 Experts available now in Live!

Get 1:1 Help Now