Hello
I wonder if someone may be able to give me some advice on the following...
I am trying to get it so that if the user clicks cancel - and chooses that they DO NOT want to save the changes... that the changes are not saved (sounds simple enough... or so I thought). I have tried a few different things, mainly the me.undo and Cancel = True... I am not sure where I am going wrong, whether I have the wrong code, the wrong event or whether its due to a lot of my fields being on sub forms but unfortunately I cannot get the cancel button working properly. It would appear that when I change the data in a field and press cancel, the changes are still saved. Arghhh!
Below are some examples of code I have used, and I have also attached my db for a fuller picture... please help
Option Compare Database
Public CancelPressed As Boolean
Option Explicit
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
ControlLocker True
Me.CmdSave.SetFocus
Me.CmdCancel.Visible = False
Me.CmdEdit.Visible = True
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.ModifiedBy = SUser
Me.ModifiedWhen = Now()
If CancelPressed = True Then
Cancel = True (note, I have also tried me.undo here)
End If
End Sub
I wonder if someone may be able to give me some advice on the following...
I am trying to get it so that if the user clicks cancel - and chooses that they DO NOT want to save the changes... that the changes are not saved (sounds simple enough... or so I thought). I have tried a few different things, mainly the me.undo and Cancel = True... I am not sure where I am going wrong, whether I have the wrong code, the wrong event or whether its due to a lot of my fields being on sub forms but unfortunately I cannot get the cancel button working properly. It would appear that when I change the data in a field and press cancel, the changes are still saved. Arghhh!
Below are some examples of code I have used, and I have also attached my db for a fuller picture... please help
Option Compare Database
Public CancelPressed As Boolean
Option Explicit
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
ControlLocker True
Me.CmdSave.SetFocus
Me.CmdCancel.Visible = False
Me.CmdEdit.Visible = True
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.ModifiedBy = SUser
Me.ModifiedWhen = Now()
If CancelPressed = True Then
Cancel = True (note, I have also tried me.undo here)
End If
End Sub