How can I set up my Access 2003 form to verify saving changes?

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

Guest

I'm using an Access 2003 form that allows me to make changes to a record and
automatically saves the changes. I would like to change the form to ask if I
want to save the changes made before I go to the next record.
 
In the form's Before Update Event:

Dim ctl As Control

If MsgBox("Do you want to save this record?", vbQuestion+vbYesNo) = vbNo then
Cancel = True
For Each ctl in Me.Controls
If ctl.ControlType = acTextBox ctl.ControlType = acComboBoxThen
ctl.Value = ctl.OldValue
End If
Next ctlTextbox
End If

If you have controls other than text or combo boxes, you will need to
include that logic as well.
 
Klatuu said:
In the form's Before Update Event:

Dim ctl As Control

If MsgBox("Do you want to save this record?", vbQuestion+vbYesNo) =
vbNo then Cancel = True
For Each ctl in Me.Controls
If ctl.ControlType = acTextBox ctl.ControlType = acComboBoxThen
ctl.Value = ctl.OldValue
End If
Next ctlTextbox
End If

If you have controls other than text or combo boxes, you will need to
include that logic as well.

No need to loop through all the controls. Just use...

Me.Undo
 
Question for you Rick. Will the Me.Undo return to values displayed in the
controls to their original values?
 
Klatuu said:
Question for you Rick. Will the Me.Undo return to values displayed
in the controls to their original values?

Yes. It "undoes" all the changes since the last save.
 
Back
Top