Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo Changes When Closing Form

Status
Not open for further replies.

JiggyPoo

Technical User
Dec 31, 2002
66
US
Hello.

How can I have the form undo any changes when the form is closed? See, I have a save button which saves the data. I want the close button to NOT save the data, but undo any changes. How do I do this?

Thank you for your help!
 
On Error GoTo Err_btnUndo_Click

'undo record
D_DI = "CA"
try something like this on your button

DoCmd.DoMenuItem Ac_FORMBAR, Ac_EDITMENU, Ac_UNDOFIELD, , Ac_MENU_VER20


'goto previous record
DoCmd.GoToRecord , , Ac_PREVIOUS

Exit_btnUndo_Click:
Exit Sub

Err_btnUndo_Click:
MsgBox Error$
Resume Exit_btnUndo_Click
 
oop's sorry it should have been this

On Error GoTo Err_btnUndo_Click

'undo record


DoCmd.DoMenuItem Ac_FORMBAR, Ac_EDITMENU, Ac_UNDOFIELD, , Ac_MENU_VER20


'goto previous record
DoCmd.GoToRecord , , Ac_PREVIOUS

Exit_btnUndo_Click:
Exit Sub

Err_btnUndo_Click:
MsgBox Error$
Resume Exit_btnUndo_Click
 
To be informative and gracefull, notify user that they have changed data on the form and may not Close form until saving or rejecting changes. Your Save button saves the data and allows record validation, force your users to use it! Close button should only close when you want it to! Do a Close click event like this:

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

If Not Me.Dirty Then
DoCmd.Close
Else
MsgBox "Save record before closing form!,vbOKOnly,
"Record is not saved!"
End If

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub

If form is not Dirty, it closes. If it is Dirty, it won't close until user saves or discards changes to record.

There are a million ways to do this but this is simple. Sorry about the formatting of this code.

aflat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top