Hi All,
I have built a save button into my form, with the following code;
However the BeforeUpdate event doesn't always fire when the button is clicked, it seems to do it randomly. I've tried adding in Call Form_BeforeUpdate with and without the call command yet when I do this, the button just does nothing, no error codes, nothing at all.
Any ideas? Thanks guys
I have built a save button into my form, with the following code;
Code:
Option Compare Database
Public txtClicked As String
Private Sub cmdSave_Click()
If Me.Dirty Then
txtClicked = "Yes" 'SAVE button has been pressed
If MsgBox("Do you wish to save?", vbYesNo, "DST PLANNER") = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
txtClicked = "No" 'Reset value, ready for further changes
End If
Else
MsgBox "No additions or changes made. No need to save anything", , "DST PLANNER"
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
If txtClicked = "Yes" Then
MsgBox "Saved!", , "DST PLANNER"
'SAVE button was clicked - allow update to continue.
Else
If Me.NewRecord Then
MsgBox "You must press the SAVE button to save this record."
Else 'Existing record being modified
MsgBox "You must press the SAVE button to modify this record."
End If
DoCmd.CancelEvent
End If
End Sub
However the BeforeUpdate event doesn't always fire when the button is clicked, it seems to do it randomly. I've tried adding in Call Form_BeforeUpdate with and without the call command yet when I do this, the button just does nothing, no error codes, nothing at all.
Any ideas? Thanks guys