A command for saving records - why?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Newbie question. I always thought a record was pretty much saved as soon as
it lost focus. After reading though these newsgroups I'm noticing people
using a save record command. What is the purpose? When should this be done?
I've been using my db for years without any such code - am I lucky I haven't
had a meltdown or is this ok?

Thanks for the knowledge.

Aaron G
Philadelphia, PA
 
Access *should* save the record automatically when it needs it, e.g. moving
record, closing form, closing Access, switching to design view, applying a
filter, changing the sort order, requerying the form, and so on.

However, there are cases where this can cause problems. The worst one is
when you use the Close action/method at a time when the can't be saved for
some reason (e.g. required field missing, validation rule not met, duplicate
index, ...) In this case, Access just silently losses the data, *without*
notifying the user. Since Access always saves, the user (quite rightly)
later believes that Access is losing their data. This data-loss flaw has
existed in Access since the beginning, and MS has still not fixed it. More
info:
http://allenbrowne.com/bug-01.html

There are less drastic cases, where Access runs into problems also. If the
user is entering something into a text box, events are being triggered
(Change, KeyDown, etc). If you now try to do something else (such as apply a
filter), there are pending events that Access has to handle, such as
BeforeUpdate, Exit, Lost Focus of the *control*, and then the BeforeUpdate
and AfterUpdate events of the form. It is these interacting events
triggering other events that can cause problems. The explicit save before
trying to do something else is a way of clearing the event queue, and so
avoiding the interaction problems.

So, Aaron, you can often get away without it, but it is good practice, and
it can help you avoid some problems that are intermittent (depending on what
events are triggered this time) and can be very hard to pin down.
 
The records on the main form are not saved until you exit the form or move to
the next record.
Sometimes you need to open another form, based on the record you are
currently working on, but you don't want to close this form, so you need to
save the records, so you can see the changes on the second form.
Or if you want to print a reprot that based on the changes that you just
made, you need to save the records and then print the report. or close the
form so the records will be saved.
 
Thanks! I'm sold. I looked at the code on the link you posted. Where
should that be put? On all forms under the "On Dirty" or "On Close"?

Thanks again.

Aaron G
Philadelphia, PA
 
The problem applies only where the Close action is used in a macro, or the
Close method is used in VBA code. In either of those cases, you need to
preceed the action/code with saving the record.

It's not an issue if the form is closed through the interface--unless you go
back to Access 1 or 2.
 
Aaron G said:
Newbie question. I always thought a record was pretty much saved as soon
as
it lost focus.

Well, more specify, when you move to another record, or close the form, the
record is saved. A form loosing focus does not necessary save the record.

After reading though these newsgroups I'm noticing people
using a save record command. What is the purpose?

There is little purpose, except to annoy the users. The problem here is that
many users come from using word, or excel, and you have to SAVE the data
when you are done. So, when those people come to ms-access, they are at a
loss as to why no save commend is needed. So, all of a sudden, you got a ton
of people asking for save code when they DO NOT NEED any at all.

Worse, is these save prompts are usually VERY VERY VERY annoying. For
example, can you imagine if you turn the key in your car, and then the car
pop up a message saying:

do you want to start the car?

How about the save concept:
You open a file cabinet, put a document into it, and the file
cabinet says do you really want to file the document?

This is sheer nuts, and is just pure annoyance by amateurs developers that
seek to annoy users, and just cause them pain.

Successful commercial products like palm pilots,a nd applications like
ms-access DO NOT annoy the users with a save prompts.

When you use outlook express, and hit the send button, a copy of the email
is actually saved in the outbox...but are you prompted for a save? (no). So,
ms-access got this right more then 10 years ago.

The fact of the matter is, that users ACTIONS should tell the software what
to do. I mean, why on earth is a user trying to move to the next record
without saving the current record? (answer: of course the user wants the
record saved...why else would they move on?). So, save the record for
them...(if they don't want to save changes..then go edit->undo).

So, as rule, you don't have to worry. The many people asking for "save" code
are simply people who need to annoy the end user with a annoying save
prompts OVER AN OVER AND OVER all day long.

The fact is, ms-access got it right..and you got it right also.....(that
being that things should get saved automatically).

Using code to save a record is often a different issue then all the
questions about save prompts, and I don't want you to get confused here. So,
99% of those questions are people who want to annoy people.

There is certainly times when you want to force a record save, but again no
prompts need occur. For example, we OFTEN get the question in this newsgroup
on how to print the ONE record you are viewing to a report. The code to do
this often given is:


docmd.OpenReport "myReport",,,"id = " & me!id

In fact, the above code is not 100% good, since the one record you are
editing has NOT been saved to disk,a nd the report will NOT show you
changes. So, the above should be written as:

me.Refresh
docmd.OpenReport "myReport",,,"id = " & me!id

In fact, in place of me.refresh, most point out it is better to use

if me.Dirty = true then
me.Dirty = false
end if
docmd.OpenReport "myReport",,,"id = " & me!id

So, there are some times when you most certainly want to force a data
save..but keep that concept from the many zillions of people who come and
ask for silly save prompts to make life annoying....
 
On Fri, 12 Aug 2005 11:29:15 -0600, "Albert D.Kallal"

<lots of good stuff>

The one drawback of saving things automatically is that accidental
changes can be saved without the user noticing. IMHO it's usually best
to handle this by keeping the forms or controls locked, with an "Edit"
button to unlock them. Once in "edit mode", however, changes are saved
without prompting if the user closes the form or moves to another
record.
 
Back
Top