Save/Cancel

  • Thread starter Thread starter Christopher Glaeser
  • Start date Start date
C

Christopher Glaeser

I need some help (suggestioned reading or link to a tutorial) on how to
implement Save/Cancel buttons on a form so that edits to a record are only
updated with the Save button. Using Access 2003. Thanks in advance for any
assistance.

Best,
Christopher
 
Cancel button's Click event procedure is simple:
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name

There are so many ways that the record in the form can be saved that the
only way to catch them all is to cancel the BeforeUpdate event of the form
it you are not happy. Since you must run all your record-level validation
checks in Form_BeforeUpdate, the question then arises as to why you are
going to force the user to save only with your button. Why not just use the
built-in event, and allow the user the freedom to use Windows the way they
already know instead of forcing them into your straight-jacket?

If you want to block all saves except through your button:
1. In the General Declaration section of the form's module (top, with Option
statements):
Dim bOk2Close As Boolean

2. In the Click event procedure of your command button:
Private Sub cmdSave_Click()
On Error Goto Err_Handler
bOk2Close = True
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close acForm, Me.Name
Exit_Handler:
Exit Sub
Err_Handler:
bOk2Close = False
Resume Exit_Handler
End Sub

3. In Form_BeforeUpdate:
If Not bOk2Close Then
Cancel = True
MsgBox "Ya havta click the Save button before you're allowed
out."
End If
 
Because of how forms work in ms-access (they can't be easily rolled into a
transaction), then you might use some caution in implementing a save button.


If any of your forms will use a sub-form, then simply clicking on, or even
just hitting tab, or the enter key to move into the sub-form triggers a
record write of the main form. Ms-access HAS TO SAVE the parent record,
since a sub-form represents the "child" records of a one to many
relationship. That means before you add ANY child records, you must FIRST
SAVE the parent, or main record. (in other words, you can't put relational
data into a table unless the records for the relation is saved BEFORE you
add child records).

However, a user of your application does not understand relational
databases. All they see is a customer invoice. They don't see the sub-form
records as a one to many relationship, but simply see a nice form (lets say
a invoice form in our example).

So, a user can be looking at a invoice form, modify the persons phone
number, and then click (or tab) into the sub-form to start entering some
details of the invoice. At this point, the main record will be saved by
ms-access...but the user decides not hit some dumb save button yet!

So, be very aware that if any of your application is going to use sub-forms,
then adding, or training, or teaching users to assume to hit a save button
might be a very bad idea.

Further, people are used to using products like excel, and moving around
with the cursor. The problem here is that excel is ONE document. Any kind of
grid, or "details" data in ms-access might look like a grid, but in fact
EACH ROW is ONE record. So, if the hit the down arrow, are you going to
force them to hit some save button? Just moving from one record to the next
in a grid (that looks like excel) in fact cases each record to be saved if
you edit the record.

You should like do what outlook does, and have a button called

Save and close

In fact, palm pilots, Outlook,and much software today does not ask you to
save...but gives you a "done concept" button.

So, I would be VERY careful in how you implement this save button
idea....and if you are using sub-forms, then the save button will not be
needed, and worse yet...will confuse the user.

The user will say...hum, I am not finished entering the data in this
invoice..and it wants me to save? Why?

I mean, when you close a form, you obviously want to save. Can you imagine
putting a key in the car, and then turning the key, and then the car asks
you do you want to start the car? If a user closes a form...why on earth
would you ask them to save?

ms-access is now more then 10 years old, and finally we see a LOT of new
software that behaves just like ms-access....and saving is implied, and is
assumed by default. The desingers of ms-access were right on in this
regards..and amaing..the rest of the industry is moving in the same
direction...

I would put much thought into the issue of using a save buttion
here..........
 
Why not just use the built-in event, and allow the user the freedom to use
Windows the way they already know instead of forcing them into your
straight-jacket?

I'm new to Access and wanted to implement features similar to Outlook
contacts and Quickbook invoices. One of the reasons I chose Commence (PIM)
over Act! and Goldmine is because of the Save/Cancel feature. In Act! and
Goldmine, if a user accidentally overtypes information into the wrong fields
of a record, there is no way to restore the correct data. When editing a
contact in Outlook, if you mangle a record during an update, you have the
option to hit cancel and start over. It's the same in Commence, Quicken,
Quickbooks, and many other apps. I prefer this paradigm. Is this feature
difficult for an Access beginner to implement?

Best,
Christopher
 
ms-access is now more then 10 years old, and finally we see a LOT of new
software that behaves just like ms-access....and saving is implied, and is
assumed by default. The desingers of ms-access were right on in this
regards..and amaing..the rest of the industry is moving in the same
direction...

Interesting. I prefer the "Save and Close" feature of Outlook contacts.
The Act! and Goldmine paradigm of "any and all edits are updating the
database" is tedious for me. Is it possible to easily implement
Outlook-style contacts in Access?

Best,
Christopher
 
Christopher Glaeser said:
Interesting. I prefer the "Save and Close" feature of Outlook contacts.
The Act! and Goldmine paradigm of "any and all edits are updating the
database" is tedious for me. Is it possible to easily implement
Outlook-style contacts in Access?

Easily? No.
 
Is it possible to easily implement Outlook-style contacts in Access?
Easily? No.

OK, that's good to know. Thanks for the quick response.

Best,
Christopher
 
Christopher Glaeser said:
I'm new to Access and wanted to implement features similar to Outlook
contacts and Quickbook invoices. One of the reasons I chose Commence
(PIM) over Act! and Goldmine is because of the Save/Cancel feature.
In Act! and Goldmine, if a user accidentally overtypes information
into the wrong fields of a record, there is no way to restore the
correct data. When editing a contact in Outlook, if you mangle a
record during an update, you have the option to hit cancel and start
over. It's the same in Commence, Quicken, Quickbooks, and many other
apps. I prefer this paradigm. Is this feature difficult for an
Access beginner to implement?

Just as a side note, in case you'd overlooked it -- it's easy to undo
unwanted changes to a record, up until the point the user takes some
action to save the record. There's an Undo menu item on the Edit menu,
and an Undo button on the toolbar, and the Esc key undoes first the
current control, then the whole form.

So it is not the case that "if a user accidentally overtypes information
into the wrong fields of a record, there is no way to restore the
correct data." The difference is that, if the user takes some action
that can reasonably be expected to represent acceptance of what has been
entered on the form -- such as closing the form, or moving to a new
record -- then the record is saved. This is what data entry personnel
want -- it's an enormous time-waster to have to click a separate button
to confirm that you want to save the data you entered.

Yes, it is possible to set up an Access form that will only save if you
click a Save button. But extra programming is necessary to do it.
There's no simple option you can set.
 
Just as a side note, in case you'd overlooked it -- it's easy to undo
unwanted changes to a record, up until the point the user takes some
action to save the record.

Many thanks for the follow up. I was unaware of the undo feature.

Best,
Christopher
 
Interesting. I prefer the "Save and Close" feature of Outlook contacts.

Yes, I find that the outlook is good. Remember, if you put a close button on
a ms-access form, or simply whack the "X" in the upper right hand corner,
then in fact you are do tithe same as outlook:

Save and close

So, I just saying that closing a form implies the save. You can put a
"close" button or a button with the picture of the exit door..but for all
terms, closing a form in ms-access means:

Save and close
Is it possible to easily implement Outlook-style contacts in Access?

I kind thought that I just explained that closing a ms-access form is the
same as the "save and close" button you have in outlook. So, I guess the
answer is yes (might not be sure what you mean by Outlook-style?....but the
save and close button most used in outlook is the same concept of closing a
form in ms-access).

A user does not hit save, and then hit another button to close the form. I
think that would be dumb, just like turning a key in a car, and then the car
asks do you want to start the car! We can be thankful that software
developers did not make cars...and put extra silly prompts and things like
so many software people do!

Can you imagine that hitting the down-arrow key in a excel sheet would
prompt the user to save the current line? How about a save button for EACH
CELL?? The same goes for ms-access, you edit a record, and then move to
the next record, but you don't get a stupid save prompt. I mean, you hit a
hit down-arrow to move to the next record in continues form view...are we
going to prompt the user to save? So, having a save button on a ms-access
form is not needed...is it? The way Outlook, and ms-access work is that you
don't need to hit save before you close.....and that seems to be the right
way to go.

And, as mentioned, since we can't wrap (easily) a form in a transaction,
then moving from the main form to a sub-form one MUST do a disk write of the
main form. I actually admit that if we could easily roll back the
form/sub-form edits...then I would accept the "idea" or suggestion for a
save button, but we can't make the save button work for both the sub-form,
and main form at the same time. Hence, we just put in a exit button...which
in fact really means save and close. I really wish some clean solutions were
available in this area. However, since I hate the idea of hitting a save
button, and THEN having to close the form...then the fact that ms-access
don't work well at all when trying to make a save button is no loss at all!
 
Is it possible to easily implement Outlook-style contacts in Access?
I kind thought that I just explained that closing a ms-access form is the
same as the "save and close" button you have in outlook. So, I guess the
answer is yes (might not be sure what you mean by Outlook-style?....but
the save and close button most used in outlook is the same concept of
closing a form in ms-access).

Outlook contacts have both "Save and Close" and Cancel "X" buttons that
save/cancel the edits of a contact record. I just now built the Access
Template "Contact Management". I am new to Access so I don't know all the
features, but when I open an existing contact record, make a few edits, hit
the cancel "X" button, then open the record again, the edits have been
recorded. This is very different behavior from Outlook. A cancel "X" in
Outlook does not record the edits to a contact record.

Hitting Ctl-Z several times will back out the edits of an Access record, so
I'm guessing there is a way to add a Cancel button to back the edits as
well, but it appears from this thread it is not easy to implement.

Best,
Christopher
 
Christopher Glaeser said:
Outlook contacts have both "Save and Close" and Cancel "X" buttons
that save/cancel the edits of a contact record. I just now built the
Access Template "Contact Management". I am new to Access so I don't
know all the features, but when I open an existing contact record,
make a few edits, hit the cancel "X" button, then open the record
again, the edits have been recorded. This is very different behavior
from Outlook. A cancel "X" in Outlook does not record the edits to a
contact record.

Hitting Ctl-Z several times will back out the edits of an Access
record, so I'm guessing there is a way to add a Cancel button to back
the edits as well, but it appears from this thread it is not easy to
implement.

Best,
Christopher

The "X" button at the upper right corner of a form isn't a Cancel
button; it's just a Close button, and the normal function of Access
when you close a form is to save the record if it has been edited.
Making the form's Close button behave as a Cancel button is quite
doable, but it requires some VBA coding that is just the other side of
trivial. Implementing your own, separate Cancel button, on the other
hand, is easier. Just create the button and create this event procedure
for its Click event:

Private Sub cmdCancel_Click()

If Me.Dirty Then
Me.Undo
End If

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub
 
Implementing your own, separate Cancel button, on the other
hand, is easier. Just create the button and create this event procedure
for its Click event:

Private Sub cmdCancel_Click()

If Me.Dirty Then
Me.Undo
End If

DoCmd.Close acForm, Me.Name, acSaveNo

End Sub

Excelent. I'll give it a try. Many thanks!!!

Best,
Christopher
 
Outlook contacts have both "Save and Close" and Cancel "X" buttons that
save/cancel the edits of a contact record. I just now built the Access
Template "Contact Management". I am new to Access so I don't know all the
features, but when I open an existing contact record, make a few edits,
hit the cancel "X" button, then open the record again, the edits have been
recorded. This is very different behavior from Outlook. A cancel "X" in
Outlook does not record the edits to a contact record.

Hum..what version of outlook? In my version when you hit the "X", you get
prompted for a save. And, by this "X" I mean the upper right hand corner
that virtually all open windows have. So, in outlook if you do edit the
record, and then hit the "X" in the upper right corner..then in fact outlook
DOES prompt for a save. So, this is a bit different then access. However, I
was trying to point out that hitting "save and close" on a outlook form is
the same as hitting "X" on a access for. And, further, if you do hit the
upper right "x" to close in outlook...you will be prompted for a save. (so,
yes..that is different behavior then ms-access...but if at this point you
hit yes..then the results are the same as ms-access). However, I don't see,
or am not aware how hitting the "X" in outlook does a cancel?
Hitting Ctl-Z several times will back out the edits of an Access record,
so I'm guessing there is a way to add a Cancel button to back the edits as
well, but it appears from this thread it is not easy to implement.

Actually, as mentioned, it is VERY easy to implement a cancel, but NOT if
you have a sub-form. So, my point is that 99% of users preference to hit a
save and close button. This "save and close concept is available in outlook
via the save and close button, and in ms-access it is the default when you
close a form. So, in ms-access, you can have a close button, or allow users
to hit the hitting the upper right X. Further, I have NEVER know the "X" to
be called a cancel button here??????

Anyway, the problem here is that if you start building those annoying
prompts "do you want to save", is that you then train users to expect that
when they close a form..they get a save prompt. And, you further train them
to assume that they can answer "no" to NOT save what they have done. Up this
point, you can for basic ms-access forms implement this setup very easily.
However, if you start using some sub-forms in your design, then this whole
model breaks down. The reason why it breaks down is because the main record
has to be saved before you can edit sub-form records. So, the user is going
to associate the concept of closing a form with saving what they see. They
will assume that hitting X will allow them to bail out of all the changes to
a screen. The problem is with a sub-form you can't do this..as the main form
gets saved when you go to the sub-form. So, now you edit data in the
sub-form..what happens when the user now hits the X? They will not get
prompted to save..since the record already is saved..and, they will not have
a option to bail out.....as it is too late. So, since we can't attach the
un-do to both the form and the sub-form, then prompting to save will not
make sense here...will it?

Further, in my opinion is it silly to torture users all day long with save
prompts. Give your users a un-do in the menu. And, I was also pointing out
that since we can't cancel the whole form changes (with a sub-form), then we
can't really use the save button when you have a sub-form..and to be
honest...I kind like this fact..since then ms-access is forced to work the
way I think it should!!!

The standard "edit" menu does have a cancel (and it is the same as the
ctrl-z that you pointed out). I generally steal those menu items even for my
own applications (so, yes, you should include the un-do edit options in YOUR
applications also). If you take a look at the following ms-access menus
(scroll down to the last screen shot), you will in fact that did put in the
un-do options (I just coped the built in ones).

http://www.attcanada.net/~kallal.msn/Articles/UseAbility/UserFriendly.htm
 
Hum..what version of outlook? In my version when you hit the "X", you get
prompted for a save. And, by this "X" I mean the upper right hand corner
that virtually all open windows have. So, in outlook if you do edit the
record, and then hit the "X" in the upper right corner..then in fact
outlook DOES prompt for a save.

Yes, and that is the behavior I prefer. Other apps I use including
Commence, Quicken, and Quickbooks are similar.
So, this is a bit different then access.

Agreed. That's why I wanted to change the Access behavior.
If you take a look at the following ms-access menus (scroll down to the
last screen shot), you will in fact that did put in the un-do options (I
just coped the built in ones).

http://www.attcanada.net/~kallal.msn/Articles/UseAbility/UserFriendly.htm

Thanks. I'll take a look.

Best,
Christopher
 
Back
Top