I have a problem similar to that in thread702-1453633 where user 'sheuz' was trying to "Provide the user with the option to save/undo changes made to the record in the form." The code I'm having trouble with is similar to sheuz's (myYesNoQPlus is a public function that simplifies creation of a message box so all that's needed is the statement text and any text for the title bar):
All over the internet and in numerous Access guides it's suggested to use code on BeforeUpdate to capture saves, but in thread702-1453633 it's basically said this is a bad idea and in essence doesn't work (I'm having trouble getting it to work - selecting 'No' in the message box doesn't stop data changes - even using all kinda reworking of the code -- for example everything in the record gets deleted with a recoding attempt using DoCmd.RunCommand acCmdUndo)
In thread702-1453633 alternate code is provided by user 'TheAceMan1'. He suggests:
But if BeforeUpdate isn't being used, what would make this code do anything? I may be using the wrong terms to express what I don't understand (I'm a sad noob) or I'm just ignorant for the same reason, but: what would trigger the message box using the above code -- which I guess is just typed into the form module somewhere? Clarification would be appreciated!
C. Reyes
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If myYesNoQPlus("Changes have been made" & vbCrLf & _
"on this Professional." & vbCrLf & vbCrLf & _
"Do you want to save these changes?", "Changed Data!") = vbNo Then
Undo 'undo changes
Cancel = True 'cancel Save
Else
'Acess will automatically save the record
End If
End Sub
All over the internet and in numerous Access guides it's suggested to use code on BeforeUpdate to capture saves, but in thread702-1453633 it's basically said this is a bad idea and in essence doesn't work (I'm having trouble getting it to work - selecting 'No' in the message box doesn't stop data changes - even using all kinda reworking of the code -- for example everything in the record gets deleted with a recoding attempt using DoCmd.RunCommand acCmdUndo)
In thread702-1453633 alternate code is provided by user 'TheAceMan1'. He suggests:
Code:
Dim Msg As String, Style As Integer, Title As String, DL As String
DL = vbNewLine & vbNewLine
Msg = "Changes have been made to this record." & DL & _
"Do you want to save these changes?"
Style = vbQuestion + vbYesNo
Title = "User Response Required! . . ."
If MsgBox(Msg, Style, Title) = vbNo Then
Cancel = True
Me.Undo
End If
But if BeforeUpdate isn't being used, what would make this code do anything? I may be using the wrong terms to express what I don't understand (I'm a sad noob) or I'm just ignorant for the same reason, but: what would trigger the message box using the above code -- which I guess is just typed into the form module somewhere? Clarification would be appreciated!
C. Reyes