Undoing Changes in subforms

wjoc1

Registered User.
Local time
Today, 10:47
Joined
Jul 25, 2002
Messages
117
I have a form that has two subforms. I have a button that exits out of this form, when the user clicks it it first "undo's" any changes made and then exits (I have a specific button for saving also). I have the following code in the OnClick event of this button:


'Runs an Undo command to undo any changes
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

'Closes the window
DoCmd.Close

However I need to undo any changes made in either of the two subforms as well, how do I do this?

Thanks,
Liam
 
When you enter the changes to the subform, as soon as the form loses focus, the record is saved.

The easy way around this is to ask for confirmation for changes whenever the subform is changed by using the before_Update event of the subform.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim response As Variant
response = MsgBox("Save (Y/N)", vbYesNo, "Save")
Select Case response
Case vbNo
Me.Undo
End Select

End Sub

This will then trap when the next button is pressed etc and allow you to cancel. The downside is that it will always ask for confimation if you make any changes.
 

Users who are viewing this thread

Back
Top Bottom