Cancel button not working

access7

Registered User.
Local time
Today, 08:39
Joined
Mar 15, 2011
Messages
172
Good Morning

I wondered if someone could spare some time to look at the following, I cannot understand why this is not working...

Quick Background: I have a main form, comprising of several sub forms. On the bottom of the main form I have a Cancel Button. I have the following code on the Main Form...

Option Compare Database
Public CancelPressed As Boolean
Option Explicit

Private Sub Form_BeforeUpdate(Cancel As Integer)
If CancelPressed = True Then
Cancel = True
End If
End Sub

Private Sub CmdCancel_Click()

MsgBox "Are you sure you want to cancel any changes?", vbQuestion + vbYesNo, "Cancel?"
If vbYes Then
CancelPressed = True
Else
DoCmd.CancelEvent
End If


ControlEnabler False - these refer to arrays which set the enabled / locked
ControlLocker True properties of some controls on the forms

Me.CmdSave.SetFocus

Me.CmdCancel.Visible = False
Me.CmdEdit.Visible = True

End Sub


The above code does not appear to be working as the changes once the cancel button has been pressed still remain (in the table and on the form).

I would like to instances ideally, one where if a user has edited an existing record they can cancel / undo their changes ... and one for is they are adding a completely new record and then decide that they wish to cancel the whole record.

I am not sure whether having the subforms is going to cause issues; would I need cancel events on the subforms or would they be 'covered' in the code on the main form??

I have attached my database in case any needs to see if there is anything else which may be stopping this from working properly...

Many Thanks in anticipation...
 

Attachments

You can't just cancel everything. If you have added any information in any of the subforms after entering in the main form, just moving to the subform saves the data in the main form. Then moving to the main form from the subform will save the data that was entered in the subform. You would need to use delete queries (or have cascade deletes set in the relationships between the parent and child tables) and delete each of the applicable pieces. You can't just undo.
 

Users who are viewing this thread

Back
Top Bottom