Cancelling Add or Update of Records

  • Thread starter Thread starter Jody
  • Start date Start date
J

Jody

I have some data entry forms on which I want to have Save
and Cancel buttons. In browsing the newsgroups, I have
seen that if you want to cancel the update or addition of
new records, you have to use a temporary table, because
Access "automatically saves the record you are adding or
editing as soon as you move the insertion point to a
different record, or close the form or datasheet you are
working on".

How would this work? Right now, each data entry form is
linked to a specific table. How do I "divert" the info to
a temporary table?

Thanks in advance.
Jody
 
You might not need to worry about this. Access will only save the
current record when you leave the record or explicitly save it. Until
then (meaning, while you are making changes to the record) you can hit
Escape or call the Undo method and the record will return to its
original state.
If, on the other hand, you need multi-level Undo for several records,
parent-child records, etc. you still need not temporary tables. Take a
look at Transactions in Help instead.

Cheers,
Pavel
 
I have some data entry forms on which I want to have Save
and Cancel buttons. In browsing the newsgroups, I have
seen that if you want to cancel the update or addition of
new records, you have to use a temporary table, because
Access "automatically saves the record you are adding or
editing as soon as you move the insertion point to a
different record, or close the form or datasheet you are
working on".

How would this work? Right now, each data entry form is
linked to a specific table. How do I "divert" the info to
a temporary table?

Thanks in advance.
Jody
there is no need for a temporary table. For the Save button just
use...

If Me.Dirty Then Me.Dirty = False

For the Cancel button use ...

Me.Undo

If you want to have the user confirm "accidental" updates the use the
form's Before Update event ...

If MsgBox("Save Changes?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Me.Undo
End If

To keep the above from triggering each time the Save button is clicked
use a module level boolean variable. (In the declarations area of the
module)...

Dim mblnDoSave As Boolean

Set it to true when the Save button is clicked. Set it back to false
in the form's After Update event.

So you would have something like this...

Private Sub cmdSaveRecord_Click()
mblnDoSave = True
If Me.Dirty Then Me.Dirty = False
End Sub


Private Sub Form_BeforeUpdate(Cancel As Integer)
If mblnDoSave = False Then
If MsgBox("Save Changes?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Me.Undo
End If
End If
End Sub

Private Sub Form_AfterUpdate()
mblnDoSave = False
End Sub


- Jim
 
Back
Top