Hello all,
I have a main form with many subforms and I am looking for help with saving the data via buttons. I have 3 custom buttons on the main form: Previous Record, Next Record, and Save Record. I am looking for the best way to prompt a person, if they have made any changes any field in either the main form or any of the sub forms, to save their info or undo the changes.
Currently, I have it working to prompt to save when either the Previous or next buttons are clicked using this code in the OnClick funtion of (borrowed from another thread-thanks!):
If Me.Dirty Then Call SaveChanges(Cancel)
If Cancel = True Then Me.Undo
The SaveChanges Sub is:
Cancel = False
If MsgBox("Do you want to save your changes?", vbYesNo) = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Cancel = True
End If
This works well, only if there is a change on the main form. But if someone changes/adds to a subform, it doesn't prompt to save. The record is saved, but I want the option to undo. I tried playing around with the BeforeUpdate on the subforms to get it to call the SaveChanges sub, but I can't get it to work correctly.
Any help is much appreciated.
Thx
I have a main form with many subforms and I am looking for help with saving the data via buttons. I have 3 custom buttons on the main form: Previous Record, Next Record, and Save Record. I am looking for the best way to prompt a person, if they have made any changes any field in either the main form or any of the sub forms, to save their info or undo the changes.
Currently, I have it working to prompt to save when either the Previous or next buttons are clicked using this code in the OnClick funtion of (borrowed from another thread-thanks!):
If Me.Dirty Then Call SaveChanges(Cancel)
If Cancel = True Then Me.Undo
The SaveChanges Sub is:
Cancel = False
If MsgBox("Do you want to save your changes?", vbYesNo) = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Else
Cancel = True
End If
This works well, only if there is a change on the main form. But if someone changes/adds to a subform, it doesn't prompt to save. The record is saved, but I want the option to undo. I tried playing around with the BeforeUpdate on the subforms to get it to call the SaveChanges sub, but I can't get it to work correctly.
Any help is much appreciated.
Thx