Event procedures and when they fire off.

M

MNJoe

Can someone explain or point to a document that explains when each of the
event procedures fires. AfterUpdate, BeforeUpdate, on dirty, on click etc
etc. I am a bit confused as to which one to use for different things. I can
program very well and do a lot of validation of input. Checking dates, if
null or entered values. Just need to get a better hand on which event
procedure to use when.

Thanks
 
A

Allen Browne

Use the BeforeUpdate event of the *form* to do most of your validation.
Access fires this just before the record is saved, so it's your last chance
to do validation. It's the only event to use to check for nulls (since the
control's events don't fire if you don't visit the control), and to compare
values between fields (since you don't know the order of entry.) And I find
it to be less annoying for users than telling them, "Ya got it wrong!" as
soon as they leave a control (particularly as they can't get out of the
control if you cancel its BeforeUpdate.) You also want to use
Form_BeforeUpdate to assign any logging values (who changed this record last
and when that was) -- there's no point using Form_AfterUpdate for this, as
it dirties the record immediately again immediately it is saved.

That's about 90% of what you need to do. Use Form_AfterUpdate to respond to
a record's edit (e.g. to write an audit in another table), or
Form_AfterInsert to respond to a new entry (e.g. to assign default roles in
a related table when you add a new client.) Use Form_BeforeInsert to cancel
a new record before it starts (e.g. to disallow a subform entry if the main
form is at a new record.)

Use Form_Current to do something when you change to a different record (e.g.
to show/hide controls), and Form_Undo to reset it (based on the OldValue.) I
don't use Form_Dirty as it has not been available/reliable in older
versions.

The form's Click is a way to catch clicking on the record selector: if you
click on the form, you'll actually fire the (Detail?) section's Click event.
You can use the MouseMove events to simulate a mouse-over if you wish.

Form_KeyDown is a way to catch/destroy keystrokes (e.g. to substitute a
single-quote for the double-quote character if you don't want to get caught
with embedded double-quotes in your strings.)

That's probably the main ones.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top