save/unsave subform in a form

aabbbcc

Registered User.
Local time
Yesterday, 23:49
Joined
Nov 14, 2015
Messages
28
i want to add a code to ask people to save it or not after they update their form or subform..

I use the following code:
__________________________________________________ ___
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strResponse As String
If Me.Dirty Then
Select Case MsgBox( _
Prompt:="Data have updated" & _
vbCrLf & "Sure to save it?", _
Buttons:=vbExclamation Or vbYesNo)
Case vbYes
DoCmd.RunCommand acCmdSave
Case vbNo
DoCmd.RunCommand acCmdUndo
End Select
End If
End Sub
______________________________________________
Private Sub Save_Click()
FormDirty = False
DoCmd.RunCommand acCmdSave
End Sub
______________________________________________

But it only works on the main form, but ignore the update of subform.
what should I add in odder to have a effect on subform also??
 
Most of your code isn't doing what you think.

acCmdSave saves the design of the form, not the data.
acCmdUndo is like pressing the undo button. It will do more than undo the changes to a record.

On a bound form, saving the record happens automatically when you leave the record unless you stop it. Moving between form and subform is enough to make a record save.

Consequently a much more elaborate technique is required. Some posters will tell you to use temporary tables but by far the best technique is to use Transacted Bound Forms. Search this site for that term to see some examples of the code.

Doing it for form and subform is not simple so be prepared for a steep learning curve.

Better to forget the save question and just tell your users that their changes are saved automatically when they move to another record because that is how databases work. If they don't want the changes then they shouldn't enter them.
 

Users who are viewing this thread

Back
Top Bottom