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...
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...