Hello when I close a form I would like to confirm whether the user wishes to save the data, if changes have been made.
I have researched the OnDirty event.
I am wondering whether it is best to tie the code to the Before Update event on the form or to the click event of the my forms Close button (I have disabled the forms control box to prevent the X being used to close).
Also are there any suggestions for improving the code - in particular I am uncertain that the error handling is correct.
Many thanks for your comments and suggestions.
Regards Mark
I have researched the OnDirty event.
I am wondering whether it is best to tie the code to the Before Update event on the form or to the click event of the my forms Close button (I have disabled the forms control box to prevent the X being used to close).
Also are there any suggestions for improving the code - in particular I am uncertain that the error handling is correct.
Many thanks for your comments and suggestions.
Regards Mark
Code:
Private Sub btn_Vend_Close_DblClick(Cancel As Integer)
'Checks to see if data has changed and if it has whether the user wants to save or undo the record, then closes
On Error GoTo Error_Handle
'if record has been changed the dirty property will be true
If Me.Dirty = True Then
'Ask if record should be saved
If MsgBox("The record has changed - do you want to save it?", _
vbYesNo + vbQuestion, [TempVars]![tVars_dB_MsgBox_Title]) = vbNo Then
Me.Undo
DoCmd.Close acForm, "frm_SA_Tab_Vendor"
MsgBox "Your changes were NOT saved"
Else
DoCmd.Close acForm, "frm_SA_Tab_Vendor"
MsgBox "Your changes WERE saved"
End If
End If
If Me.Dirty = False Then
DoCmd.Close acForm, "frm_SA_Tab_Vendor"
End If
Error_Handle:
Exit Sub
End Sub