use of 'on current/open/activate/load etc events (1 Viewer)

Real Wally

Registered User.
Local time
Today, 01:31
Joined
Jan 28, 2003
Messages
107
Hi all,

Are there particular advantages/disadvantages for the use of the various on current, on open, on load, on activate etc. events for a form? To me it seems as if there is not much difference between them but that's probably plain ignorance from my site, why else would the different choices have been created?

Thanks,
Wally
 
There are important differeces between those events. You need to check the Access help files for each event to see what they have to offer.

Here is a blurb copied from the help files for the Open event...

When you first open a form, the following events occur in this order:
Open Þ Load Þ Resize Þ Activate Þ Current

If you're trying to decide whether to use the Open or Load event for your macro or event procedure, one significant difference is that the Open event can be canceled, but the Load event can't. For example, if you're dynamically building a record source for a form in an event procedure for the form's Open event, you can cancel opening the form if there are no records to display. Similarly, the Unload event can be canceled, but the Close event can't.

HTH
 
Hi, Thanks for your reply.
I'll read the help files more carefully. I did have a look at them before (just a really quick look in fact) but didn't spot the main issues. From the bits and pieces of code snippets I've gotten from this site and others I had the impression that people just picked one over the other more or less without a real reason, almost like whatever came to mind first.

Obviously, the cancel issues are important, and there are probably more. Thanks for putting me on the right track (and stimulating me to put the extra time in discovering the typical issues for each of them).

Wally
 
In no particular order:


OnOpen

This event is triggered when the form is open but before the first record is displayed which is handy as you can use it to check if there are indeed any records to show - if not, you can use it's Cancel integer to cancel the opening of the form.


OnLoad

This event occurs when the form is open and its record(s) are displayed. Here you can set the values of controls or do calculations with records displayed on the form.


OnCurrent

Triggered by navigation through a recordset or refreshing a form, this event sets the focus to a record making it the current record. With this event you can use it to display messages, calculate details, and (my personal favourite) to synchronise details with other records.


OnActivate

This occurs when the window your form is in becomes the active window. I've never used it myself but I can see it being handy for setting a TimerInterval when the form has the focus and using its opposite event to switch off the timer when the form is not active.



Still similar?
 
Well, they all perform different functions, "On current " happens when you move to a new record. That's somewhat different to "On Open", I think you'll agree. Some events allow a an argument to cancel the event if some validation is not satisfied, others don't take arguments. "Open" happens before data is loaded, "Load" occurs after the recordsource is opened and "activate" occurs whenever the form receives the focus. The code you write will be optimized to take advantage of the timing of each of these events.
 
And thank you too Mile and AncientOne

No, not similar anymore.
But ,...

I've set values for controls in both 'on current' and 'on open' that you say should be in 'on load'. I've seen numerous examples of this in other peoples codes and being a self starter with just a handbook on Access that doesn't explain these things that confused me as they all seem to work just fine.

I am starting to understand the importance of standarisation (the hard way, much axtra work) and I'd like to get this right too.

Wally
 
It is important to note that the Open and Load events occur only once when the form is opened, whereas the Current event occurs every time the record pointer is moved. If you never navigate to other records with your form, you would not notice that your code was in the improper event.

Get in the habit of using the "correct" event even in cases where it does not matter. Just take a look at all the posts by people trying to do validation. They consistantly make the mistake of using the LostFocus, Dirty, or Change events and don't understand why their code doesn't work.
 

Users who are viewing this thread

Back
Top Bottom