save changes to form and subform

ReginaF

Registered User.
Local time
Today, 10:02
Joined
Sep 23, 2019
Messages
26
Hello Everybody!

I am back with a new "problem". So I am now working on form with a subform. I added a saveBtn to my main form, and I would like to only save changes made to the form or the subform if I click the saveBtn and then click yes to the appearing messagebox. I have successfully implemented this with only one main form. If just click save (and Me.Dirty = True) then a msgbox will appear and if I click yes it will save changes, if no, then it will discard all changes made. Now when I tried to update my code to do the same if I make changes to the main form or the subform. However no matter what I try it will only ask to save changes if I only edit the main form. If I edit both or only the subform, then when I click on the saveBtn it automatically saves all, without asking if I really want to save changes.
My code it the following:

If Me.Dirty = True Then
If MsgBox(" Mented a változtatásokat mainben?", vbYesNo) = vbYes Then
Me.Dirty = False
Else
Me.Undo
End If
ElseIf Me.Dirty And Me.frm_Sub_Szövet.Form.Dirty = True Then
If MsgBox(" Mented a változtatásokat mindenhol?", vbYesNo) = vbYes Then
Me.Dirty = False
Me.frm_Sub_Szövet.Form.Dirty = False
'with this we force access to save changes
Else
Me.Undo
Me.frm_Sub_Szövet.Form.Undo
End If
ElseIf Me.frm_Sub_Szövet.Form.Dirty = True Then
If MsgBox(" Mented a változtatásokat subban?", vbYesNo) = vbYes Then
Me.frm_Sub_Szövet.Form.Dirty = False
'with this we force access to save changes
Else
Me.frm_Sub_Szövet.Form.Undo
End If
End If

It would be really important for me to only save changes if I press okay and if no is pressed, then all changes made should be discarded. I would really appreciate any kind of help.
Thank you in advance!

Regina
 
Hi Regina. If you really want to control when a record should be saved to the table, then your best bet is to use unbound forms.
 
Thank you for your hint. But is there no other way? I am really unfamiliar with unbounf forms and how I can save records with them.
I had success with simple forms (using my code above), I only can not implement it to forms containing subforms :(
 
Thank you for your hint. But is there no other way? I am really unfamiliar with unbounf forms and how I can save records with them.
I had success with simple forms (using my code above), I only can not implement it to forms containing subforms :(
I'm afraid any other way would be just as problematic. The good thing about using bound forms is that Access automatically saves the record for you. So, when the user leaves the subform after dirtying it, Access automatically saves the data. But since you don't want that, then you'll have to stop Access from doing it. And the only reliable way to do that, since you want to consider the data on the main form too, is to use unbound forms.


One other approach is to bind the subform to a temp table. When the user clicks the "Save" button on the main form, you then save or move the data from the temp table to the appropriate child table.
 

Users who are viewing this thread

Back
Top Bottom