Hello all!
The following code was working, but I was experimenting with some different ideas and decided to go back to my original setup. Unfortunately, the code does not want to cooperate anymore.
When it would ask if I want to "Save" and I click "No", then it would clear the data and not save, but now it does not clear the data fields and it will Save the data anyways.
No matter what I try, it saves the data input when I click "No."
The form is used to add a new record.
Here is the code for the form and controls:
I am hoping someone can see what is askew (besides me).
Thanks ahead of time.
The following code was working, but I was experimenting with some different ideas and decided to go back to my original setup. Unfortunately, the code does not want to cooperate anymore.
When it would ask if I want to "Save" and I click "No", then it would clear the data and not save, but now it does not clear the data fields and it will Save the data anyways.
No matter what I try, it saves the data input when I click "No."
The form is used to add a new record.
Here is the code for the form and controls:
Code:
Option Compare Database
Option Explicit
Private blnSave As Boolean
Private Sub cmdCancel_Click()
On Error GoTo cmdCancel_Click_Err
On Error Resume Next
DoCmd.RunCommand acCmdUndo
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
cmdCancel_Click_Exit:
Exit Sub
cmdCancel_Click_Err:
MsgBox Error$
Resume cmdCancel_Click_Exit
End Sub
Private Sub cmdExitAddNewEMS12_Click()
On Error GoTo cmdExitAddNewEMS12_Click_Err
DoCmd.Close , ""
DoCmd.OpenForm "frmEMS22Alt"
cmdExitAddNewEMS12_Click_Exit:
Exit Sub
cmdExitAddNewEMS12_Click_Err:
MsgBox Error$
Resume cmdExitAddNewEMS12_Click_Exit
End Sub
Private Sub cmdSaveEMS22_Click()
blnSave = MsgBox("Are you sure you want to save this record?", vbQuestion + vbYesNo, "Save Confirmation")
DoCmd.RunCommand acCmdSaveRecord
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not blnSave Then
Cancel = True
Me.Undo
End If
End Sub
I am hoping someone can see what is askew (besides me).
Thanks ahead of time.
Last edited: