Which Form Event should I use?

L

LA Lawyer

I am trying to trigger code when I change records in a form (this is the
exact opposite of "OnCurrent"). I always thought that it was
"BeforeUpdate", but that is not being triggered (nor is "AfterUpdate").
Those do work but only when the form is dirty (i.e., I changed some data on
the form). I need to know the event to trigger code when I change records
even if I don't make any changes.
 
A

Albert D. Kallal

LA Lawyer said:
I am trying to trigger code when I change records in a form (this is the
exact opposite of "OnCurrent"). I always thought that it was
"BeforeUpdate", but that is not being triggered (nor is "AfterUpdate").
Those do work but only when the form is dirty (i.e., I changed some data on
the form). I need to know the event to trigger code when I change records
even if I don't make any changes.


The events only fire if the user makes some changes. I think it goes without
saying that if no changes are made to the form's data, then we would not
want the before update event to fire. In other words, the way it works makes
perfect sense. The forms before update event WILL fire if you dirty (modify)
the value of some value in code. However, controls before update events
don't fire, and it would darn near remove the ability of any code to modify
a value on a form without a zillion un-expected things occurring.

The question is what code is running that is making this change? Since the
code "knows" that is just changed something, then it is the responsibility
of that code to run any additional code you need/plan to run in the before
update event in a control.

However, in a form, the before update event will fire. For controls, it not
the case, nor in 99% of the cases would you want this to occur...

Do expand on if you talking about code that modifies a control on the form,
or code that modifies the underlying data that the form is bound to?

It just not clear when or how this code you speak is being run, and it
within the context of who, or what this code is running lies the appropriate
solution.
 
L

LA Lawyer

I have added some code to do a lot of things that, frankly, I should have
included in the beginning. Now, I have a lot of records and want to run
thru them and "catch up" what I should have done earlier.
 
A

Albert D. Kallal

LA Lawyer said:
I have added some code to do a lot of things that, frankly, I should have
included in the beginning. Now, I have a lot of records and want to run
thru them and "catch up" what I should have done earlier.

Excellent..that makes more sense.

In the above case, in most cases what you'll do then is not bother using the
actual four minutes events, this is far too difficult, far too clumsy, and
in most case it just doesn't really work. think of the banking system in
which they have to do some calculations on your accounts, they don't fire up
all the instant teller machines around the world and watched the little
forms do all kinds of dancing and flashing on the screens on the instant
teller machines as they want to update some of that data.

if you need to update some of the data in the tables, then write some
routines or update queries that modifies that code, it's inappropriate nor
even practical to attempt to use the form itself to go through and modified
a whole bunch of records at one time. forms are used interactivity with the
user, and can be programmed clear on to go and modify a whole bunch of
existing data.

Fortunately for your case there's ample programming update abilities built
into access and most database systems. So, you can and want to batch update
large numbers of records and modify their values.

say for example if you have a bunch of records that you need to modify some
city that was entered incorrectly, let's assume that you have a city name
and the value of

N. Y.

But, what you really wanted enter into that field was New York.

What you can do is create an update query. Simply fire up the query, drop in
the table, drop in that one column name "city" into the grid. you then in
the menu option choose query, then choose an update query

for the update to value, you type in

New York

And, for the condition field, you type in N. Y.

Now when you run this update query it'll update just those records with N.
Y. to New York.

you can also in theory to simply type in the SQL of such as

update tblCustomers set City = 'New York' where city = 'N. Y.'

And if you have a couple more complex conditions, you can even write some
code here. So in the data processing world it's extremely rare and generally
not even considered possible to try and make your form "run" for all of the
data in your database system, no more than a banking system trying to fire
up all the instant tellers all around the world to try and update the data.

Data processing just don't work that way.

So if you're need more complex conditions to modify existing records do
simply feel free to ask how would you update such and such records to such
and such values with such and such conditions. So batch updates or large
wholesale upating of many records is rarely if ever done through a form.
Forms are not designed nor even appropriate to attempt these kind of updates
on many records.
 

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